public ListModelBase <HealthPlanCallQueueViewModel, HealthPlanCallQueueListModelFilter> GetHealthPlanCallQueueList(int pageNumber, int pageSize, ModelFilterBase filter, out int totalRecords) { var assignmentFilter = filter as HealthPlanCallQueueListModelFilter ?? new HealthPlanCallQueueListModelFilter(); var healthPlanCallQueuesCriteria = _healthPlanCallQueueCriteriaRepository.GetHealthPlanCallQueueCriteria(filter as HealthPlanCallQueueListModelFilter, pageNumber, pageSize, out totalRecords); if (healthPlanCallQueuesCriteria == null && !healthPlanCallQueuesCriteria.Any()) { totalRecords = 0; return(null); } var callQueueIds = healthPlanCallQueuesCriteria.Select(cq => cq.CallQueueId).ToArray(); var healthPlanIds = healthPlanCallQueuesCriteria.Where(x => x.HealthPlanId.HasValue).Select(s => s.HealthPlanId.Value).ToArray(); IEnumerable <CorporateAccount> healthPlans = null; if (healthPlanIds != null && healthPlanIds.Any()) { healthPlans = _corporateAccountRepository.GetByIds(healthPlanIds); } IEnumerable <CallQueue> healthPlanCallQueues = null; if (callQueueIds != null && callQueueIds.Any()) { healthPlanCallQueues = _callQueueRepository.GetByIds(callQueueIds, false, true); } var assignOrgRoleIds = healthPlanCallQueuesCriteria.Select(a => a.DataRecorderMetaData.DataRecorderCreator.Id).Distinct().ToArray(); var modifiedBy = healthPlanCallQueuesCriteria.Where(x => x.DataRecorderMetaData.DataRecorderModifier != null).Select(a => a.DataRecorderMetaData.DataRecorderModifier.Id).Distinct().ToArray(); if (modifiedBy != null && modifiedBy.Any()) { assignOrgRoleIds = assignOrgRoleIds.Concat(modifiedBy).ToArray(); } var criteriaIds = healthPlanCallQueuesCriteria.Select(s => s.Id).ToArray(); IEnumerable <HealthPlanCriteriaAssignment> healthPlanCriteriaAssignment = null; IEnumerable <HealthPlanCriteriaTeamAssignment> healthPlanCriteriaTeamAssignment = null; var campaignIds = healthPlanCallQueuesCriteria.Where(s => s.CampaignId.HasValue).Select(x => x.CampaignId.Value).ToArray(); var campaigns = _campaignRepository.GetByIds(campaignIds); if (criteriaIds != null && criteriaIds.Any()) { healthPlanCriteriaAssignment = _healthPlanCriteriaAssignmentRepository.GetByCriteriaIds(criteriaIds); healthPlanCriteriaTeamAssignment = _healthPlanCriteriaTeamAssignmentRepository.GetByCriteriaIds(criteriaIds); if (healthPlanCriteriaAssignment != null && healthPlanCriteriaAssignment.Any()) { var assignAssignmentRoleUserIds = healthPlanCriteriaAssignment.Select(s => s.AssignedToOrgRoleUserId).Distinct().ToArray(); if (assignAssignmentRoleUserIds != null && assignAssignmentRoleUserIds.Any()) { assignOrgRoleIds = assignOrgRoleIds.Concat(assignAssignmentRoleUserIds).ToArray(); } var assignmentBy = healthPlanCriteriaAssignment.Select(s => s.CreatedBy).Distinct().ToArray(); if (assignmentBy.Any()) { assignOrgRoleIds = assignOrgRoleIds.Concat(assignmentBy).ToArray(); } } } IEnumerable <OrderedPair <long, string> > teamIdNamePairs = null; if (!healthPlanCriteriaTeamAssignment.IsNullOrEmpty()) { teamIdNamePairs = _callCenterTeamRepository.GetIdNamePairOfTeams(healthPlanCriteriaTeamAssignment.Select(x => x.TeamId).ToArray()); var assignmentBy = healthPlanCriteriaTeamAssignment.Select(s => s.CreatedBy).Distinct().ToArray(); if (assignmentBy.Any()) { assignOrgRoleIds = assignOrgRoleIds.Concat(assignmentBy).ToArray(); } } assignOrgRoleIds = assignOrgRoleIds.Distinct().ToArray(); var agentIdNamePairs = _organizationRoleUserRepository.GetNameIdPairofUsers(assignOrgRoleIds); var criteriaCustomerCountPairs = new List <OrderedPair <long, long> >(); if (assignmentFilter.ShowAssignmentMetaData) { foreach (var criteria in healthPlanCallQueuesCriteria) { var count = _customerCallQueueCallAttemptService.CustomerCountForHealthPlanCriteria(criteria, healthPlanCallQueues); criteriaCustomerCountPairs.Add(new OrderedPair <long, long>(criteria.Id, count)); } } var criteriaDirectMailDates = _healthPlanCriteriaDirectMailService.GetDirectMailDatesByCriteriaIds(criteriaIds); return(_callQueueListModelFactory.CreateHealthPlanCallQueueList(healthPlanCallQueuesCriteria, agentIdNamePairs, healthPlanCallQueues, healthPlans, healthPlanCriteriaAssignment, campaigns, healthPlanCriteriaTeamAssignment, teamIdNamePairs, criteriaCustomerCountPairs, criteriaDirectMailDates, assignmentFilter.ShowAssignmentMetaData)); }
public IEnumerable <CallCentreAgentQueueListViewModel> CallCenterAgentDashboardData(CallCentreAgentQueueFilter filter, int pageNumber, int pageSize, out int totalRecords) { var criteriaCollection = _callQueueCriteriaRepository.GetAgentAssignedCallQueueCriteria(filter); if (criteriaCollection.IsNullOrEmpty()) { totalRecords = 0; return(null); } //to find distinct list of healthplanIds just group them and select first of each such group var healthPlanIds = criteriaCollection.Select(x => x.HealthPlanId).Distinct(); var healthPlanNameIdPairList = _corporateAccountRepository.HealthPlanNamesCorrepondingToHealthPlanIds(healthPlanIds); var callQueues = _callQueueRepository.GetByIds(criteriaCollection.Select(x => x.CallQueueId).Distinct(), false, true); var campaignIds = criteriaCollection.Where(x => x.CampaignId.HasValue).Select(x => x.CampaignId.Value).ToList(); var campaigns = _campaignRepository.GetByIds(campaignIds); var criteriaIds = criteriaCollection.Select(x => x.Id).ToArray(); //Eliminating those criterias for which Number of Customers are ZERO var criteriasToExclude = new List <long>(); foreach (var criteria in criteriaCollection) { var count = CustomerCountForHealthPlanCriteria(criteria, callQueues, true); if (!(count > 0)) { criteriasToExclude.Add(criteria.Id); } } criteriaCollection = criteriaCollection.Where(x => !criteriasToExclude.Contains(x.Id)).Select(x => x); //uncomment this to make this work(except fillevent) //Take criterias according to our paging pageNumber = pageNumber <= 0 ? 1 : pageNumber; totalRecords = criteriaCollection.Count(); criteriaCollection = criteriaCollection.Skip(pageSize * (pageNumber - 1)).Take(pageSize); var assignments = _healthPlanCriteriaAssignmentRepository.GetByCriteriaIds(criteriaIds); var teamAssignments = _healthPlanCriteriaTeamAssignmentRepository.GetByCriteriaIds(criteriaIds); var criteriaDirectMailDates = _healthPlanCriteriaDirectMailService.GetDirectMailDatesByCriteriaIds(criteriaCollection.Select(x => x.Id)); //putting data into our View model to be returned var listModel = new List <CallCentreAgentQueueListViewModel>(); foreach (var item in criteriaCollection) { var model = new CallCentreAgentQueueListViewModel(); var healthPlan = healthPlanNameIdPairList.First(x => x.FirstValue == item.HealthPlanId); var callQueue = callQueues.First(x => x.Id == item.CallQueueId); var campaign = item.CampaignId.HasValue ? campaigns.First(x => x.Id == item.CampaignId.Value) : null; var assignmentDate = assignments != null?assignments.FirstOrDefault(x => x.HealthPlanCriteriaId == item.Id && x.AssignedToOrgRoleUserId == filter.AgentOrganizationRoleUserId) : null; var teamAssignmentDate = teamAssignments != null?teamAssignments.FirstOrDefault(x => x.HealthPlanCriteriaId == item.Id) : null; var directMailDates = criteriaDirectMailDates.Where(x => x.FirstValue == item.Id).Select(x => x.SecondValue); model.CriteriaName = callQueue.Category == HealthPlanCallQueueCategory.FillEventsHealthPlan || callQueue.Category == HealthPlanCallQueueCategory.AppointmentConfirmation ? item.CriteriaName : (callQueue.Category == HealthPlanCallQueueCategory.MailRound ? campaign.Name : healthPlan.SecondValue + " " + callQueue.Name); model.CriteriaId = item.Id; model.HealthPlanName = healthPlan.SecondValue; model.HealthPlanId = healthPlan.FirstValue; model.CallQueueName = callQueue.Name; model.CallQueueId = callQueue.Id; model.CapmaignId = item.CampaignId; model.CampaignName = campaign != null ? campaign.Name : string.Empty; if (assignmentDate != null) { model.StartDate = assignmentDate.StartDate; model.EndDate = assignmentDate.EndDate; } else if (teamAssignmentDate != null) { model.StartDate = teamAssignmentDate.StartDate; model.EndDate = teamAssignmentDate.EndDate; } model.DirectMailDates = directMailDates; listModel.Add(model); } return(listModel); }