public EventBasicInfoListModel GetEventBasicInfoForCallQueue(FillEventsCallQueueFilter filter, int pageSize, out int totalRecords)
        {
            var criteria = _healthPlanCallQueueCriteriaService.GetSystemGeneratedCallQueueCriteria(filter.CallQueueId, filter.HealthPlanId, filter.AssignedToOrgRoleUserId, 0, filter.CriteriaId);

            if (criteria != null && criteria.IsQueueGenerated == false)
            {
                throw new Exception("Please wait for 10 minutes(max) after you have changed the criteria so that the queue is regenerated.");
            }
            var events = _eventRepository.GetHealthPlanEventsForCallQueue(filter, criteria.Id);

            if (events == null || !events.Any())
            {
                totalRecords = 0;
                return(null);
            }

            var endDate = DateTime.Today.AddDays(criteria.NoOfDays);

            events = events.Where(x => x.EventDate.Date <= endDate.Date);

            var outboundCallQueueFilter = new OutboundCallQueueFilter
            {
                CallQueueId   = criteria.CallQueueId,
                CriteriaId    = criteria.Id,
                HealthPlanId  = criteria.HealthPlanId ?? 0,
                Radius        = 25,
                GmsAccountIds = _settings.GmsAccountIds
            };

            _healthPlanOutboundCallQueueService.GetAccountCallQueueSettingForCallQueue(outboundCallQueueFilter);

            var eventIdsWithCustomers = _callQueueCustomerRepository.GetHealthPlanEventsForCriteria(outboundCallQueueFilter);

            events = events.Where(x => (eventIdsWithCustomers.IsNullOrEmpty() || eventIdsWithCustomers.Contains(x.Id)));

            events       = _fillEventsCallQueueHelper.GetAllTheEventFilledUnderPecentage(events, criteria.Percentage);
            totalRecords = events.Count();
            events       = events.OrderBy(ev => ev.EventDate).Skip((filter.PageNumber - 1) * pageSize).Take(pageSize);

            var eventList = _eventCallQueueHelper.EventBasicInfoListForCallQueue(events);

            return(eventList);
        }
Beispiel #2
0
        public IEnumerable <CallQueueCustomer> GetCallQueueCustomers(long callQueueId, SystemGeneratedCallQueueCriteria criteria)
        {
            var days       = criteria.NoOfDays;
            var percentage = criteria.Percentage;

            var endDate = DateTime.Today.AddDays(days);

            var eventList = _eventRepository.GetEventsForFillEventsCallQueue(endDate);

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

            eventList = _fillEventsCallQueueHelper.GetAllTheEventFilledUnderPecentage(eventList, percentage);
            if (eventList == null || !eventList.Any())
            {
                return(null);
            }

            var eventIds = eventList.Select(x => x.Id);

            var eventZipPairList = new List <OrderedPair <long, string> >();

            var hostList = _hostRepository.GetEventHosts(eventIds);

            foreach (var theEvent in eventList)
            {
                var host = hostList.FirstOrDefault(h => h.Id == theEvent.HostId);
                if (host != null)
                {
                    eventZipPairList.Add(new OrderedPair <long, string>(theEvent.Id, host.Address.ZipCode.Zip));
                }
            }

            var zipList = eventZipPairList.Select(x => x.SecondValue).Distinct().ToList();
            var zipZipStringPairList = new List <OrderedPair <string, string> >();

            foreach (var zip in zipList)
            {
                var zipCodesInRange = _zipCodeRepository.GetZipCodesInRadius(zip, 10) ??
                                      new List <ZipCode>();
                if (!zipCodesInRange.Any())
                {
                    zipZipStringPairList.Add(new OrderedPair <string, string>(zip, "," + zip + ","));
                }
                else
                {
                    var zipCodestring = "," + string.Join(",", zipCodesInRange) + ",";
                    zipZipStringPairList.Add(new OrderedPair <string, string>(zip, zipCodestring));
                }
            }
            var customers = _customerRepository.GetCustomerForFillEventCallQueue(eventZipPairList, zipZipStringPairList);

            var pcustomers = _prospectCustomerRepository.GetProspectCustomerForFillEventCallQueue(eventZipPairList, zipZipStringPairList);

            if ((customers == null || !customers.Any()) && (pcustomers == null || !pcustomers.Any()))
            {
                return(null);
            }

            var callQueueCustomerList = new List <CallQueueCustomer>();

            if (customers != null && customers.Any())
            {
                foreach (var customer in customers)
                {
                    callQueueCustomerList.Add(new CallQueueCustomer {
                        CallQueueId = callQueueId, EventId = customer.FirstValue, CustomerId = customer.SecondValue
                    });
                }
            }

            if (pcustomers != null && pcustomers.Any())
            {
                foreach (var pcustomer in pcustomers)
                {
                    if (callQueueCustomerList.Any(cqcl => cqcl.CustomerId == pcustomer.CustomerId && cqcl.EventId == pcustomer.EventId))
                    {
                        continue;
                    }
                    callQueueCustomerList.Add(new CallQueueCustomer {
                        CallQueueId = callQueueId, ProspectCustomerId = pcustomer.ProspectCustomerId, CustomerId = pcustomer.CustomerId, EventId = pcustomer.EventId
                    });
                }
            }


            return(callQueueCustomerList);
        }