using Hotline.CallCenter.Calls; using Hotline.Share.Enums.CallCenter; using Hotline.Share.Notifications; using MediatR; namespace Hotline.Application.Handlers.CallCenter.FlowControl { public class ByeExtAndOuterTwoNotificationHandler : INotificationHandler { private readonly ICallRepository _callRepository; private readonly ICallDetailRepository _callDetailRepository; public ByeExtAndOuterTwoNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository) { _callRepository = callRepository; _callDetailRepository = callDetailRepository; } public async Task Handle(ByeExtAndOuterTwoNotification notification, CancellationToken cancellationToken) { var model = await _callRepository.GetAsync( x => x.ConversationId == notification.Outer.Id && x.ToNo == notification.Outer.To && x.Trunk==notification.Outer.Trunk && x.CreationTime>=DateTime.Now.AddHours(-2), cancellationToken); if (model != null) { model.CallStatus = ECallStatus.Bye; model.EndBy = EEndBy.To; model.RingOffType = ERingOffType.Normal; await _callRepository.UpdateAsync(model, cancellationToken); var detail = new CallDetail() { CallId = model.Id, CallStatus = ECallStatus.Bye, OMCallId = notification.Outer.CallId, ConversationId = notification.Outer.Id, EventName = notification.Attribute, FromNo = notification.Outer.From, ToNo = notification.Outer.To, Recording = notification.Recording }; await _callDetailRepository.AddAsync(detail, cancellationToken); } } } }