public void PollForCallQueue()
        {
            try
            {
                _logger.Info("Entering Single Health Plan Call Round Polling Agent");
                var callQueue = _callQueueRepository.GetCallQueueByCategory(HealthPlanCallQueueCategory.CallRound);
                var criterias = _healthPlanCallQueueCriteriaService.GetHealthPlanCallQueueCriteriaNotGenerated(callQueue.Id);

                var healthPlanIds = criterias.Where(x => x.HealthPlanId != null).Select(x => x.HealthPlanId.Value).ToArray();
                var healthPlans   = _corporateAccountRepository.GetByIds(healthPlanIds);

                foreach (var criteria in criterias)
                {
                    try
                    {
                        _healthPlanCallQueueAssignmentRepository.DeleteByCriteriaId(criteria.Id);

                        if (criteria.HealthPlanId.HasValue)
                        {
                            var healthPlan = healthPlans.First(x => x.Id == criteria.HealthPlanId.Value);
                            _healthPlanCallRoundService.SaveCallRoundCallQueueCustomers(healthPlan, criteria, callQueue, _logger);
                        }

                        criteria.IsQueueGenerated       = true;
                        criteria.LastQueueGeneratedDate = DateTime.Now;

                        _healthPlanCallQueueCriteriaService.Save(criteria);
                    }
                    catch (Exception exception)
                    {
                        _logger.Error(string.Format("Error while generating call queue customer data for Criteria Id: {0} \n message: {1} stack trace {2}", criteria.Id, exception.Message, exception.StackTrace));
                    }
                }

                callQueue.IsQueueGenerated       = true;
                callQueue.LastQueueGeneratedDate = DateTime.Now;
                _callQueueRepository.Save(callQueue);
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Error while pulling single call round call queue. Message {0} \n Stack Trace {1}", ex.Message, ex.StackTrace));
            }
        }
        public void PollForHealthPlanCallQueue()
        {
            try
            {
                _logger.Info("Entering Health Plan Polling Agent To Generate Call Queue For CallRound, NoShows and ZipRadius");

                var callQueues  = _callQueueRepository.GetAll(false, true);
                var healthPlans = _corporateAccountRepository.GetAllHealthPlan();

                if (!callQueues.IsNullOrEmpty())
                {
                    callQueues = callQueues.Where(x => x.Category != HealthPlanCallQueueCategory.FillEventsHealthPlan && x.Category != HealthPlanCallQueueCategory.UncontactedCustomers &&
                                                  x.Category != HealthPlanCallQueueCategory.MailRound);

                    foreach (var callQueue in callQueues)
                    {
                        try
                        {
                            var criteria = _healthPlanCallQueueCriteria.GetQueueCriteriasByQueueId(callQueue.Id);
                            criteria = criteria.Where(x => x.IsQueueGenerated);

                            switch (callQueue.Category)
                            {
                            case HealthPlanCallQueueCategory.CallRound:
                            {
                                foreach (var queueCriteria in criteria)
                                {
                                    try
                                    {
                                        _healthPlanCallQueueAssignment.DeleteByCriteriaId(queueCriteria.Id);

                                        if (queueCriteria.HealthPlanId.HasValue && !healthPlans.IsNullOrEmpty())
                                        {
                                            var corporateAccount = healthPlans.First(x => x.Id == queueCriteria.HealthPlanId.Value);
                                            _healthPlanCallRoundService.SaveCallRoundCallQueueCustomers(corporateAccount, queueCriteria, callQueue, _logger);
                                        }
                                        queueCriteria.IsQueueGenerated       = true;
                                        queueCriteria.LastQueueGeneratedDate = DateTime.Now;
                                        _healthPlanCallQueueCriteria.Save(queueCriteria);
                                    }
                                    catch (Exception exception)
                                    {
                                        _logger.Error("call Queue Id " + callQueue.Id);
                                        _logger.Error("criteria Id " + queueCriteria.Id);
                                        _logger.Error("Message " + exception.Message);
                                        _logger.Error("Stack Trace " + exception.StackTrace);
                                    }
                                }
                            }
                            break;

                                //case HealthPlanCallQueueCategory.NoShows:
                                //    {
                                //        foreach (var queueCriteria in criteria)
                                //        {
                                //            try
                                //            {
                                //                _healthPlanCallQueueAssignment.DeleteByCriteriaId(queueCriteria.Id);

                                //                if (queueCriteria.HealthPlanId.HasValue && !healthPlans.IsNullOrEmpty())
                                //                {
                                //                    var corporateAccount = healthPlans.First(x => x.Id == queueCriteria.HealthPlanId.Value);
                                //                    _healthPlanCallRoundService.SaveNoShowCallQueueCustomers(corporateAccount, queueCriteria, callQueue, _logger);
                                //                }
                                //                queueCriteria.IsQueueGenerated = true;
                                //                queueCriteria.LastQueueGeneratedDate = DateTime.Now;
                                //                _healthPlanCallQueueCriteria.Save(queueCriteria);
                                //            }
                                //            catch (Exception exception)
                                //            {
                                //                _logger.Error("call Queue Id " + callQueue.Id);
                                //                _logger.Error("criteira Id " + queueCriteria.Id);
                                //                _logger.Error("Message " + exception.Message);
                                //                _logger.Error("Stack Trace " + exception.StackTrace);
                                //            }

                                //        }
                                //    }
                                //    break;
                                //case HealthPlanCallQueueCategory.ZipRadius:
                                //    {
                                //        foreach (var queueCriteria in criteria)
                                //        {
                                //            _healthPlanCallQueueAssignment.DeleteByCriteriaId(queueCriteria.Id);

                                //            if (queueCriteria.IsDefault)
                                //            {
                                //                foreach (var corporateAccount in healthPlans)
                                //                {
                                //                    _healthPlanCallRoundService.SaveHealthPlanZipRadiusCallQueueCustomers(corporateAccount, queueCriteria, callQueue, _logger);
                                //                }
                                //            }
                                //            else if (queueCriteria.HealthPlanId.HasValue && !healthPlans.IsNullOrEmpty())
                                //            {
                                //                var corporateAccount = healthPlans.First(x => x.Id == queueCriteria.HealthPlanId.Value);
                                //                _healthPlanCallRoundService.SaveHealthPlanZipRadiusCallQueueCustomers(corporateAccount, queueCriteria, callQueue, _logger);
                                //            }
                                //            queueCriteria.IsQueueGenerated = true;
                                //            queueCriteria.LastQueueGeneratedDate = DateTime.Now;
                                //            _healthPlanCallQueueCriteria.Save(queueCriteria);
                                //        }
                                //    }
                                //    break;
                            }
                        }
                        catch (Exception exception)
                        {
                            _logger.Error(string.Format("error health plan call queue. callQueueId: {0} ", callQueue.Id));
                            _logger.Error(string.Format("Message {0} stack trace: {1} ", exception.Message, exception.StackTrace));
                        }
                        callQueue.IsQueueGenerated       = true;
                        callQueue.LastQueueGeneratedDate = DateTime.Now;
                        _callQueueRepository.Save(callQueue);
                    }
                }
            }
            catch (Exception exception)
            {
                _logger.Error(string.Format("error health plan call queue."));
                _logger.Error(string.Format("Message {0} stack trace: {1} ", exception.Message, exception.StackTrace));
            }
        }