Exemplo n.º 1
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);
        }