private void ParseCallUploadedCalls(IEnumerable <DataRow> rows, List <CallUploadLog> failedCustomerList, List <CallUploadLog> successCustomerList, long callUploadId)
        {
            var callUploadLogs = rows.Select(row => _callUploadHelper.GetUploadLog(row, callUploadId));

            if (callUploadLogs.IsNullOrEmpty())
            {
                _logger.Info("No Record Found For Parsing in file");
                return;
            }

            SaveFailedCustomers(failedCustomerList, callUploadLogs);

            callUploadLogs = callUploadLogs.Where(x => x.IsSuccessfull);

            if (callUploadLogs.IsNullOrEmpty())
            {
                _logger.Info("No Successfull Customer Found For Parsing in file");
                return;
            }
            var customerIds = callUploadLogs.Select(x => x.CustomerId).Distinct();

            var outboundCustomerIds = callUploadLogs.Where(x => !x.IsDirectMail).Select(x => x.CustomerId).ToArray();

            IEnumerable <Customer> customers = null;

            try
            {
                customers = _customerRepository.GetCustomers(customerIds.ToArray());
            }
            catch (Exception ex)
            {
                _logger.Error(" Exception : " + ex.Message + " \n Stack Trace: " + ex.StackTrace);
            }

            if (customers != null && customers.Any())
            {
                var healthPlans = _corporateAccountRepository.GetAllHealthPlan();

                var events = ((IUniqueItemRepository <Event>)_eventRepository).GetByIds(callUploadLogs.Where(x => x.EventId > 0).Select(x => x.EventId).ToArray());

                var callQueue = _callQueueRepository.GetCallQueueByCategory(HealthPlanCallQueueCategory.CallRound);

                var callQueueCustomers = _callQueueCustomerRepository.GetCallQueueCustomersBuCustomerIds(outboundCustomerIds, callQueue.Id).ToList();

                var prospectCustomers = _prospectCustomerRepository.GetProspectCustomersByCustomerIds(outboundCustomerIds);

                var calls = _callCenterCallRepository.GetCallDetails(outboundCustomerIds);

                var emailIds = callUploadLogs.Select(x => x.Email).Distinct().ToList();

                var userNames = callUploadLogs.Where(x => !string.IsNullOrEmpty(x.UserName)).Select(x => x.UserName).Distinct().ToList();

                var organizationRoleUserEmail = _organizationRoleUserRepository.GetNameIdPairofOrgRoleIdByEmail(emailIds, (long)Roles.CallCenterRep);

                var organizationRoleUserUserName = _organizationRoleUserRepository.GetNameIdPairofOrgRoleIdByUserNames(userNames, (long)Roles.CallCenterRep);

                var directMailTypes = _directMailTypeRepository.GetAll();


                foreach (var callUploadLog in callUploadLogs)
                {
                    try
                    {
                        var customer = customers.SingleOrDefault(x => x.CustomerId == callUploadLog.CustomerId);
                        if (customer == null)
                        {
                            callUploadLog.IsSuccessfull = false;
                            callUploadLog.ErrorMessage  = "Customer ID is not valid.";
                            _callUploadLogRepository.SaveCallUploadLog(callUploadLog);
                            failedCustomerList.Add(callUploadLog);
                            continue;
                        }

                        if (string.IsNullOrEmpty(customer.Tag))
                        {
                            callUploadLog.IsSuccessfull = false;
                            callUploadLog.ErrorMessage  = "Customer does not belong to any HealthPlan.";
                            _callUploadLogRepository.SaveCallUploadLog(callUploadLog);
                            failedCustomerList.Add(callUploadLog);
                            continue;
                        }

                        var healthPlan = healthPlans.SingleOrDefault(x => x.Tag == customer.Tag);

                        if (healthPlan == null)
                        {
                            callUploadLog.IsSuccessfull = false;
                            callUploadLog.ErrorMessage  = "HealthPlan " + customer.Tag + " not found.";
                            _callUploadLogRepository.SaveCallUploadLog(callUploadLog);
                            failedCustomerList.Add(callUploadLog);
                            continue;
                        }

                        var orgRoleId = _callUploadHelper.GetOrganizationRoleId(callUploadLog, organizationRoleUserEmail, organizationRoleUserUserName);

                        if (orgRoleId <= 0)
                        {
                            callUploadLog.IsSuccessfull = false;
                            callUploadLog.ErrorMessage  = "Created By Information does not found.";
                            _callUploadLogRepository.SaveCallUploadLog(callUploadLog);
                            failedCustomerList.Add(callUploadLog);
                            continue;
                        }

                        long?directMailTypeId = null;
                        if (callUploadLog.IsDirectMail)
                        {
                            var campaign = _campaignRepository.GetCampaignByName(callUploadLog.CampaignName);

                            if (campaign == null)
                            {
                                callUploadLog.IsSuccessfull = false;
                                callUploadLog.ErrorMessage  = " Please provide a valid campaign name.";
                                _callUploadLogRepository.SaveCallUploadLog(callUploadLog);
                                failedCustomerList.Add(callUploadLog);
                                continue;
                            }

                            if (!string.IsNullOrEmpty(callUploadLog.DirectMailType))
                            {
                                var directMailType = directMailTypes.SingleOrDefault(s => s.Name.ToLower() == callUploadLog.DirectMailType.ToLower());

                                if (directMailType == null)
                                {
                                    callUploadLog.IsSuccessfull = false;
                                    callUploadLog.ErrorMessage  = " Please provide a valid Direct Mail Type.";
                                    _callUploadLogRepository.SaveCallUploadLog(callUploadLog);
                                    failedCustomerList.Add(callUploadLog);
                                    continue;
                                }
                                directMailTypeId = directMailType.Id;
                            }
                            var isInvalidAddress = false;
                            if (callUploadLog.IsInvalidAddress != null)
                            {
                                isInvalidAddress = callUploadLog.IsInvalidAddress.ToLower().Trim() == "yes" ? true : false;
                            }

                            var directMail = new DirectMail
                            {
                                CustomerId       = callUploadLog.CustomerId,
                                MailDate         = callUploadLog.OutreachDateTime.Value.Date,
                                CallUploadId     = callUploadLog.CallUploadId,
                                CampaignId       = campaign.Id,
                                DirectMailTypeId = directMailTypeId,
                                Mailedby         = orgRoleId,
                                IsInvalidAddress = isInvalidAddress,
                                Notes            = isInvalidAddress ? "Direct Mail returned because of invalid address." : string.Empty,
                            };

                            _directMailRepository.Save(directMail);
                        }
                        else
                        {
                            Event theEventData = null;
                            if (callUploadLog.EventId > 0)
                            {
                                theEventData = events.SingleOrDefault(x => x.Id == callUploadLog.EventId);
                                if (theEventData == null)
                                {
                                    callUploadLog.IsSuccessfull = false;
                                    callUploadLog.ErrorMessage  = "Event Id provide is not valid.";
                                    _callUploadLogRepository.SaveCallUploadLog(callUploadLog);
                                    failedCustomerList.Add(callUploadLog);
                                    continue;
                                }
                            }

                            if (callUploadLog.EventId > 0)
                            {
                                var isValidEventForAccount = _eventRepository.ValidateEventForAccount(callUploadLog.EventId, healthPlan.Id);
                                if (!isValidEventForAccount)
                                {
                                    callUploadLog.IsSuccessfull = false;
                                    callUploadLog.ErrorMessage  = "Event Id provide is not valid for customer HealthPlan.";
                                    _callUploadLogRepository.SaveCallUploadLog(callUploadLog);
                                    failedCustomerList.Add(callUploadLog);
                                    continue;
                                }
                            }

                            var prospectCustomer = prospectCustomers.FirstOrDefault(x => x.CustomerId == customer.CustomerId);

                            if (prospectCustomer == null && customer != null)
                            {
                                prospectCustomer = _prospectCustomerFactory.CreateProspectCustomerFromCustomer(customer, false);
                                prospectCustomer = ((IUniqueItemRepository <ProspectCustomer>)_prospectCustomerRepository).Save(prospectCustomer);
                            }

                            var callQueueCustomer = SaveCallQueueCustomer(callQueue.Id, callUploadLog, healthPlan.Id,
                                                                          callQueueCustomers);

                            var call = SaveCall(callUploadLog, theEventData != null ? theEventData.Id : 0, orgRoleId, healthPlan.Id);

                            if (prospectCustomer != null)
                            {
                                UpdateContactedInfo(prospectCustomer.Id, call.Id, orgRoleId);
                            }

                            SaveCallQueueCustomerCall(callQueueCustomer, call);
                            SaveCallNotes(callUploadLog, call.Id, orgRoleId);

                            var  customerCalls = calls.Where(x => x.CalledCustomerId == callUploadLog.CustomerId);
                            bool isRemovedFromCallQueue;
                            var  isRuleApplied = _callUploadRuleEngine.ApplyRuleEngine(callUploadLog, customerCalls, prospectCustomer, orgRoleId, callQueueCustomer.Id, callQueueCustomer.CallQueueId, out isRemovedFromCallQueue, _logger);

                            if (isRemovedFromCallQueue)
                            {
                                callQueueCustomer.Status = CallQueueStatus.Removed;
                                _callQueueCustomerRepository.Save(callQueueCustomer);
                            }

                            callUploadLog.IsRuleApplied = isRuleApplied;
                        }

                        successCustomerList.Add(callUploadLog);

                        _callUploadLogRepository.SaveCallUploadLog(callUploadLog);
                    }
                    catch (Exception ex)
                    {
                        callUploadLog.IsSuccessfull = false;
                        callUploadLog.ErrorMessage  = "Message: " + ex.Message + "\n stack Trace: " + ex.StackTrace;
                        failedCustomerList.Add(callUploadLog);
                        _logger.Error("Message: " + ex.Message + "\n stack Trace: " + ex.StackTrace);
                    }
                }
            }
            else
            {
                foreach (var callUploadLog in callUploadLogs)
                {
                    callUploadLog.IsSuccessfull = false;
                    callUploadLog.ErrorMessage  = "Please Provide a valid CustomerId";
                    failedCustomerList.Add(callUploadLog);
                }
            }


            SaveFailedCustomers(failedCustomerList, callUploadLogs);
        }
Пример #2
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);
        }
Пример #3
0
        public CampaignListModel GetCampaignDetails(int pageNumber, int pageSize, CampaignListModelFilter filter, out int totalRecords)
        {
            var campaigns = _campaignRepository.GetCampaignDetails(pageNumber, pageSize, filter, out totalRecords);

            if (campaigns == null || !campaigns.Any())
            {
                return(null);
            }

            var campaignIds = campaigns.Select(x => x.Id).ToArray();

            //IEnumerable<CampaignAssignment> campaignAssignment = null;

            //if (campaignIds != null && campaignIds.Any())
            //{
            //    campaignAssignment = _campaignAssignmentRepository.GetByCampaignIds(campaignIds);
            //}

            var campaignCreatedByIds = campaigns.Select(cg => cg.DataRecorderMetaData.DataRecorderCreator.Id).ToArray();

            var campaignModifiedByIds = campaigns.Select(cg => cg.DataRecorderMetaData.DataRecorderModifier.Id).ToArray();

            if (campaignCreatedByIds != null && campaignCreatedByIds.Any())
            {
                campaignCreatedByIds = campaignCreatedByIds.Concat(campaignModifiedByIds).ToArray();
            }

            var campaignActivity = _campaignActivityRepository.GetByCampaignIds(campaignIds);

            IEnumerable <CampaignActivityAssignment> campaignActivityAssignment = null;

            if (campaignActivity != null && campaignActivity.Any())
            {
                var campaignActivityIds = campaignActivity.Select(x => x.Id).ToArray();

                if (campaignActivityIds != null && campaignActivityIds.Any())
                {
                    campaignActivityAssignment = _campaignActivityAssignmentRepository.GetByCampaignActivityIds(campaignActivityIds).ToArray();

                    if (campaignActivityAssignment != null && campaignActivityAssignment.Any())
                    {
                        var activityAssignmentOrgRoleIds = campaignActivityAssignment.Select(x => x.AssignedToOrgRoleUserId).Distinct().ToArray();

                        campaignCreatedByIds = campaignCreatedByIds.Concat(activityAssignmentOrgRoleIds).ToArray();
                    }
                }
            }

            IEnumerable <OrderedPair <long, string> > campaignCreatedByAgentNameIdPair = null;

            if (campaignCreatedByIds != null && campaignCreatedByIds.Any())
            {
                campaignCreatedByAgentNameIdPair = _organizationRoleUserRepository.GetNameIdPairofUsers(campaignCreatedByIds).ToArray();
            }

            var directMailTypes = _directMailTypeRepository.GetAll();

            var corporateAccounts = _corporateAccountRepository.GetAllHealthPlan();

            return(_campaignListModelFactory.Create(campaigns, campaignCreatedByAgentNameIdPair, corporateAccounts, campaignActivity, campaignActivityAssignment, directMailTypes));
        }