Ejemplo n.º 1
0
        public CallQueueCustomerNotesViewModel GetCustomerNotes(long callId, long callQueueCustomerId)
        {
            var callHistoryModel = new List <CallHistoryViewModel>();

            CallQueueCustomer callQueueCustomer = null;
            long customerId         = 0;
            long prospectCustomerId = 0;

            if (callQueueCustomerId > 0)
            {
                callQueueCustomer  = _callQueueCustomerRepository.GetById(callQueueCustomerId);
                customerId         = callQueueCustomer.CustomerId ?? 0;
                prospectCustomerId = callQueueCustomer.ProspectCustomerId ?? 0;
            }
            else
            {
                var call = _callCenterCallRepository.GetById(callId);
                customerId = call != null ? call.CalledCustomerId : 0;
            }

            var calls = _callCenterCallRepository.GetCallsForCallQueueCustomer(callId, customerId, prospectCustomerId);

            if (calls != null && calls.Any())
            {
                var callCenterNotes = _callCenterNotesRepository.GetByCallIds(calls.Select(x => x.CallId));
                var agentNameIds    = _organizationRoleUserRepository.GetNameIdPairofUsers(calls.Select(x => x.CreatedByOrgRoleUserId).ToArray());

                var callHistoryList = new List <CallHistoryViewModel>();

                foreach (var customerCall in calls)
                {
                    var agentNameId = agentNameIds.First(c => c.FirstValue == customerCall.CreatedByOrgRoleUserId);

                    var dispositionValue = "N/A";

                    if (!string.IsNullOrEmpty(customerCall.Disposition))
                    {
                        ProspectCustomerTag disposition;
                        Enum.TryParse(customerCall.Disposition, out disposition);

                        if (Enum.IsDefined(typeof(ProspectCustomerTag), disposition))
                        {
                            dispositionValue = disposition.GetDescription();
                        }
                    }

                    var callHistory = new CallHistoryViewModel()
                    {
                        CallId              = customerCall.CallId,
                        DateCreated         = customerCall.CallDateTime,
                        CallOutcome         = ((CallStatus)customerCall.Status).GetDescription(),
                        RequestedCallBack   = callQueueCustomer != null ? callQueueCustomer.CallDate : (DateTime?)null,
                        CreatedBy           = agentNameId.SecondValue,
                        Disposition         = dispositionValue,
                        NotInterestedReason = customerCall.NotInterestedReasonId.HasValue ? ((NotInterestedReason)customerCall.NotInterestedReasonId).GetDescription() : "N/A"
                    };

                    if (callCenterNotes != null && callCenterNotes.Any())
                    {
                        var customerNotes = callCenterNotes.Where(ccn => ccn.CallId == customerCall.CallId).Select(ccn => ccn).ToArray();
                        callHistory.Notes = customerNotes.Select(cn => new NotesViewModel()
                        {
                            Note = cn.Notes, EnteredOn = cn.DateCreated
                        }).OrderByDescending(x => x.EnteredOn);
                    }

                    callHistoryList.Add(callHistory);
                }

                callHistoryModel.AddRange(callHistoryList.OrderByDescending(x => x.DateCreated).ToList());
            }
            var mailHistoryList = new List <DirectMailViewModel>();

            if (customerId > 0)
            {
                var directMails = _directMailRepository.GetByCustomerId(customerId);

                if (directMails != null && directMails.Any())
                {
                    var agentNameIds    = _organizationRoleUserRepository.GetNameIdPairofUsers(directMails.Select(x => x.Mailedby).ToArray());
                    var directMailTypes = _directMailTypeRepository.GetAll();

                    foreach (var directMail in directMails)
                    {
                        var agentNameId = agentNameIds.First(c => c.FirstValue == directMail.Mailedby);
                        var directMailSentToCustomer = "N/A";

                        if (directMail.DirectMailTypeId.HasValue)
                        {
                            directMailSentToCustomer = directMailTypes.Single(x => x.Id == directMail.DirectMailTypeId.Value).Name;
                        }
                        mailHistoryList.Add(new DirectMailViewModel()
                        {
                            DateCreated    = directMail.MailDate,
                            CreatedBy      = agentNameId.SecondValue,
                            DirectMailType = directMailSentToCustomer,
                            Notes          = directMail.IsInvalidAddress ? directMail.Notes : "N/A"
                        });
                    }
                }
            }

            var customerCallNotesViewModel = new List <CustomerCallNotesViewModel>();

            if (customerId > 0)
            {
                var customerCallNotes = _customerCallNotesRepository.GetCustomerNotes(customerId).ToList();

                var orders = _orderRepository.GetAllOrdersForCustomer(customerId);
                if (orders != null && orders.Count() > 0)
                {
                    var refundRequests = _refundRequestRepository.GeRefundRequestByOrderIds(orders.Select(oec => oec.Id).ToArray(), RefundRequestType.CustomerCancellation);

                    if (refundRequests != null && refundRequests.Count() > 0)
                    {
                        var refundRequestNotes = new List <CustomerCallNotes>();
                        foreach (var refundRequest in refundRequests)
                        {
                            refundRequestNotes.Add(new CustomerCallNotes
                            {
                                CustomerId           = customerId,
                                Notes                = refundRequest.Reason,
                                NotesType            = CustomerRegistrationNotesType.CancellationNote,
                                DataRecorderMetaData = new DataRecorderMetaData(refundRequest.RequestedByOrgRoleUserId, refundRequest.RequestedOn, null)
                            });
                        }
                        customerCallNotes = customerCallNotes.Concat(refundRequestNotes).ToList();
                    }
                }

                if (!customerCallNotes.IsNullOrEmpty())
                {
                    customerCallNotes = customerCallNotes.OrderByDescending(x => x.DataRecorderMetaData.DateCreated).ToList();
                    var orgRoleUserIds = customerCallNotes.Select(x => x.DataRecorderMetaData.DataRecorderCreator.Id).ToArray();
                    orgRoleUserIds = orgRoleUserIds.Distinct().ToArray();

                    var agentNameIds = _organizationRoleUserRepository.GetNameIdPairofUsers(orgRoleUserIds);

                    customerCallNotesViewModel.AddRange(from notes in customerCallNotes
                                                        let createdBy = agentNameIds.First(x => x.FirstValue == notes.DataRecorderMetaData.DataRecorderCreator.Id).SecondValue
                                                                        select GetCustomerCallNotesViewModel(notes, createdBy));
                }
            }

            var notesViewModel = new CallQueueCustomerNotesViewModel
            {
                CallHistory       = callHistoryModel,
                CustomerCallNotes = customerCallNotesViewModel,
                DirectMail        = mailHistoryList
            };

            return(notesViewModel);
        }
Ejemplo n.º 2
0
        public ActionResult CustomerCallNotes(long customerId, long eventId = 0)
        {
            var customerCallNotes = _customerCallNotesRepository.GetCustomerNotes(customerId, true);

            customerCallNotes = customerCallNotes.Where(m => (m.NotesType == CustomerRegistrationNotesType.CancellationNote || m.NotesType == CustomerRegistrationNotesType.LeftWithoutScreeningNotes) || !string.IsNullOrWhiteSpace(m.Notes));

            var cancelledCustomerNotes = customerCallNotes.Where(m => m.NotesType == CustomerRegistrationNotesType.CancellationNote);
            var eventCustomers         = _eventCustomerRepository.GetbyCustomerId(customerId);

            var cancellationLogByEventCustomers = _eventAppointmentCancellationLogRepository.GetByEventCustomerIds(eventCustomers.Select(x => x.Id));

            if (cancelledCustomerNotes.Any())
            {
                foreach (var customerCallNote in cancelledCustomerNotes)
                {
                    var cancellationNote = cancellationLogByEventCustomers.FirstOrDefault(x => x.NoteId == customerCallNote.Id);
                    customerCallNote.ReasonName = cancellationNote != null ? ((CancelAppointmentReason)cancellationNote.ReasonId).GetDescription() : "N/A";
                    //var createdBy = customerCallNote.DataRecorderMetaData != null && customerCallNote.DataRecorderMetaData.DataRecorderCreator != null ?
                    //    orgRoleUsers.FirstOrDefault(x => x.FirstValue == customerCallNote.DataRecorderMetaData.DataRecorderCreator.Id) : null;
                    //customerCallNote.CreatedBy = createdBy != null ? createdBy.SecondValue : string.Empty;
                }
            }

            if (eventId > 0)
            {
                customerCallNotes = customerCallNotes.Where(ccn => !ccn.EventId.HasValue || (ccn.EventId.HasValue && ccn.EventId.Value == eventId)).ToArray();
            }

            var orders = _orderRepository.GetAllOrdersForCustomer(customerId);

            if (orders != null && orders.Any())
            {
                var refundRequests = _refundRequestRepository.GeRefundRequestByOrderIds(orders.Select(oec => oec.Id).ToArray(), RefundRequestType.CustomerCancellation);

                if (refundRequests != null && refundRequests.Any())
                {
                    var refundRequestNotes = new List <CustomerCallNotes>();
                    foreach (var refundRequest in refundRequests)
                    {
                        var cancellationLog = cancellationLogByEventCustomers.FirstOrDefault(x => x.RefundRequestId.HasValue && x.RefundRequestId.Value == refundRequest.Id);

                        refundRequestNotes.Add(new CustomerCallNotes
                        {
                            CustomerId           = customerId,
                            Notes                = refundRequest.Reason,
                            EventId              = cancellationLog != null ? cancellationLog.EventId : (long?)null,
                            ReasonName           = cancellationLog != null ? ((CancelAppointmentReason)cancellationLog.ReasonId).GetDescription() : string.Empty,
                            NotesType            = CustomerRegistrationNotesType.CancellationNote,
                            DataRecorderMetaData = new DataRecorderMetaData(refundRequest.RequestedByOrgRoleUserId, refundRequest.RequestedOn, null),
                        });
                    }

                    customerCallNotes = customerCallNotes.Concat(refundRequestNotes);
                }
            }

            cancellationLogByEventCustomers = cancellationLogByEventCustomers.Where(x => x.NoteId == null && x.RefundRequestId == null);

            if (cancellationLogByEventCustomers != null && cancellationLogByEventCustomers.Any())
            {
                var cancellationNotesLog = new List <CustomerCallNotes>();

                foreach (var cancellationLog in cancellationLogByEventCustomers)
                {
                    cancellationNotesLog.Add(new CustomerCallNotes
                    {
                        CustomerId           = customerId,
                        EventId              = cancellationLog.EventId,
                        Notes                = string.Empty,
                        NotesType            = CustomerRegistrationNotesType.CancellationNote,
                        ReasonName           = ((CancelAppointmentReason)cancellationLog.ReasonId).GetDescription(),
                        DataRecorderMetaData = new DataRecorderMetaData(cancellationLog.CreatedBy, cancellationLog.DateCreated, null),
                    });
                }

                customerCallNotes = customerCallNotes.Concat(cancellationNotesLog);
            }

            if (!customerCallNotes.IsNullOrEmpty())
            {
                customerCallNotes = customerCallNotes.OrderByDescending(x => x.DataRecorderMetaData.DateCreated);
            }

            var patientLeftNotes = customerCallNotes.Where(x => x.NotesType == CustomerRegistrationNotesType.LeftWithoutScreeningNotes);

            if (!patientLeftNotes.IsNullOrEmpty())
            {
                foreach (var patientLeftNote in patientLeftNotes)
                {
                    patientLeftNote.ReasonName = patientLeftNote.ReasonId.HasValue ? ((LeftWithoutScreeningReason)patientLeftNote.ReasonId.Value).GetDescription() : "";
                    //var createdBy = patientLeftNote.DataRecorderMetaData != null && patientLeftNote.DataRecorderMetaData.DataRecorderCreator != null ?
                    //    orgRoleUsers.FirstOrDefault(x => x.FirstValue == patientLeftNote.DataRecorderMetaData.DataRecorderCreator.Id) : null;
                    //patientLeftNote.CreatedBy = createdBy != null ? createdBy.SecondValue : string.Empty;
                }
            }

            var orgRoleUserIds = customerCallNotes.Where(x => x.DataRecorderMetaData != null && x.DataRecorderMetaData.DataRecorderCreator != null).Select(x => x.DataRecorderMetaData.DataRecorderCreator.Id).ToArray();
            var orgRoleUsers   = _organizationRoleUserRepository.GetNameIdPairofUsers(orgRoleUserIds);

            foreach (var customerCallNote in customerCallNotes)
            {
                var createdBy = customerCallNote.DataRecorderMetaData != null && customerCallNote.DataRecorderMetaData.DataRecorderCreator != null?
                                orgRoleUsers.FirstOrDefault(x => x.FirstValue == customerCallNote.DataRecorderMetaData.DataRecorderCreator.Id) : null;

                customerCallNote.CreatedBy = createdBy != null ? createdBy.SecondValue : string.Empty;
            }

            return(View(customerCallNotes));
        }