public ListModelBase <CallQueueExcludedCustomerReportModel, CallQueueExcludedCustomerReportModelFilter> GetCallQueueExcludedCustomerReport(int pageNumber, int pageSize, ModelFilterBase filter, out int totalRecords) { var callQueueFilter = filter as CallQueueExcludedCustomerReportModelFilter; var customers = _customerRepository.GetCallQueueExcludedCustomers(callQueueFilter, pageNumber, pageSize, out totalRecords); if (customers == null || !customers.Any()) { return(null); } var customerIds = customers.Select(c => c.CustomerId).ToArray(); var customerEligibilities = _customerEligibilityRepository.GetCustomerEligibilityByCustomerIdsAndYear(customerIds, DateTime.Today.Year); if (customerEligibilities.IsNullOrEmpty()) { customerEligibilities = new List <CustomerEligibility>(); } var customTags = _corporateCustomerCustomTagRepository.GetByCustomerIds(customerIds); var prospectCustomers = _prospectCustomerRepository.GetProspectCustomersByCustomerIds(customerIds); var eventCustomers = _eventCustomerRepository.GetByCustomerIds(customerIds); eventCustomers = eventCustomers.Where(x => x.AppointmentId.HasValue && x.NoShow == false); var eventIds = eventCustomers.Select(x => x.EventId).ToArray(); var events = _eventRepository.GetEvents(eventIds); var orgRoleUsers = _organizationRoleUserRepository.GetOrganizationRoleUsers(customerIds); var userIds = orgRoleUsers.Select(x => x.UserId).ToList(); var users = _userRepository.GetUsers(userIds); var targetedCustomers = _customerTargetedRepository.GetCustomerTargetedByCustomerIdsAndYear(customerIds, DateTime.Today.Year); if (callQueueFilter.CampaignId > 0) { var zipIds = _callQueueCustomerRepository.GetAccountZip(callQueueFilter.HealthPlanId); var callQueueCustomers = _callQueueCustomerRepository.GetCallQueueCustomersForRejectedList(customerIds, callQueueFilter.CampaignId, callQueueFilter.HealthPlanId); var account = ((IUniqueItemRepository <CorporateAccount>)_corporateAccountRepository).GetById(callQueueFilter.HealthPlanId); var criterias = _healthPlanCallQueueCriteriaRepository.GetByCampaignId(callQueueFilter.CampaignId); var criteria = criterias.First(); var accountCallQueueSetting = (_callQueueSettingRepository.GetByAccountIdAndCallQueueId(callQueueFilter.HealthPlanId, criteria.CallQueueId)); return(_callQueueExcludedCustomerReportListModelFactory.Create(customers, customTags, prospectCustomers, eventCustomers, events, orgRoleUsers, users, callQueueCustomers, zipIds, account, accountCallQueueSetting, customerEligibilities, targetedCustomers)); } return(_callQueueExcludedCustomerReportListModelFactory.Create(customers, customTags, prospectCustomers, eventCustomers, events, orgRoleUsers, users, null, null, null, null, customerEligibilities, targetedCustomers)); }
public void PollForHealthPlanMailRoundCallQueue() { try { var callDate = DateTime.Now; var campaigns = new List <Campaign>(); var campaignByCallDate = _campaignRepository.GeCotporateCampaignForCallQueue(callDate); if (!campaignByCallDate.IsNullOrEmpty()) { campaigns.AddRange(campaignByCallDate); } var campaignsNotGenerated = _campaignRepository.GetCotporateCampaignForNotGenerated(); if (!campaignsNotGenerated.IsNullOrEmpty()) { var campaigIds = campaigns.Select(x => x.Id).ToArray(); if (!campaigIds.IsNullOrEmpty()) { campaignsNotGenerated = campaignsNotGenerated.Where(x => !campaigIds.Contains(x.Id)).ToArray(); if (!campaignsNotGenerated.IsNullOrEmpty()) { campaigns.AddRange(campaignsNotGenerated); } } else { campaigns.AddRange(campaignsNotGenerated); } } if (campaigns.IsNullOrEmpty()) { _logger.Info("No Campaigns found for call queue generation."); return; } var healthPlanIds = campaigns.Select(x => x.AccountId).ToArray(); var healthPlans = _corporateAccountRepository.GetByIds(healthPlanIds); foreach (var campaign in campaigns) { try { _logger.Info("Started creating Mail Round call queue for campaign: " + campaign.Name); var campaignActivites = _campaignActivityRepository.GetByCampaignId(campaign.Id); var outboundCallAcivity = campaignActivites.FirstOrDefault(ca => ca.TypeId == (long)CampaignActivityType.OutboundCall && ca.ActivityDate.Date == callDate.Date); if (outboundCallAcivity == null) { outboundCallAcivity = campaignActivites.Where(ca => ca.TypeId == (long)CampaignActivityType.OutboundCall).OrderByDescending(x => x.ActivityDate).FirstOrDefault(); } if (outboundCallAcivity == null) { continue; } var firstDirectMailActivity = campaignActivites.Where(ca => ca.TypeId == (long)CampaignActivityType.DirectMail && ca.ActivityDate <= outboundCallAcivity.ActivityDate).OrderBy(ca => ca.ActivityDate).FirstOrDefault(); if (firstDirectMailActivity == null) { _logger.Info("No Direct mail activity before outbound call."); _logger.Info("Completed creating Mail Round call queue for campaign: " + campaign.Name); continue; } var criterias = _healthPlanCallQueueCriteriaRepository.GetByCampaignId(campaign.Id); if (criterias.IsNullOrEmpty()) { _logger.Info("No Criteria has been created."); _logger.Info("Completed creating Mail Round call queue for campaign: " + campaign.Name); continue; } foreach (var campaingnCriteria in criterias) { try { if (campaingnCriteria.IsQueueGenerated && campaingnCriteria.LastQueueGeneratedDate.HasValue && campaingnCriteria.LastQueueGeneratedDate.Value.Date == callDate.Date) { _logger.Info("Call queue has been already generated for the campaign."); _logger.Info("Completed creating Mail Round call queue for campaign: " + campaign.Name); continue; } _healthPlanCallQueueAssignmentRepository.DeleteByCriteriaId(campaingnCriteria.Id); var healthPlan = healthPlans.Single(x => x.Id == campaign.AccountId); var callQueue = _callQueueRepository.GetCallQueueByCategory(HealthPlanCallQueueCategory.MailRound); _healthPlanCallRoundService.SaveMailRoundCallQueueCustomers(healthPlan, campaingnCriteria, callQueue, _logger, campaign); campaingnCriteria.IsQueueGenerated = true; campaingnCriteria.LastQueueGeneratedDate = DateTime.Now; _healthPlanCallQueueCriteriaRepository.Save(campaingnCriteria); } catch (Exception ex) { _logger.Error("Some Error Occurred While Generating Campaign Criteria Data: " + campaign.Name); _logger.Error("Message: " + ex.Message); _logger.Error("Stack Trace: " + ex.StackTrace); } } _logger.Info("Completed creating Mail Round call queue for campaign: " + campaign.Name); } catch (Exception ex) { _logger.Error("Error while Creating Mail Round call queue for campaign: " + campaign.Name); _logger.Error("Message : " + ex.Message); _logger.Error("Stack Trace : " + ex.StackTrace); } } } catch (Exception ex) { _logger.Error("Error while Polling Mail Round call queue"); _logger.Error("Message : " + ex.Message); _logger.Error("Stack Trace : " + ex.StackTrace); } }