public ListModelBase <HourlyOutreachCallReportModel, HourlyOutreachCallReportModelFilter> GetOutreachCallReport(int pageNumber, int pageSize, ModelFilterBase filter, out int totalRecords) { var calls = _callCenterCallRepository.GetOutreachCallQueueCustomer(filter as OutreachCallReportModelFilter, pageNumber, pageSize, out totalRecords); if (calls == null || !calls.Any()) { return(null); } var customerIds = calls.Select(c => c.CalledCustomerId).ToArray(); var customerEligibilities = _customerEligibilityRepository.GetCustomerEligibilityByCustomerIdsAndYear(customerIds, DateTime.Today.Year); if (customerEligibilities.IsNullOrEmpty()) { customerEligibilities = new List <CustomerEligibility>(); } var callQueueIds = calls.Where(x => x.CallQueueId.HasValue).Select(x => x.CallQueueId.Value).ToArray(); var callQueues = _callQueueRepository.GetByIds(callQueueIds, false, true); var customers = _customerRepository.GetCustomers(customerIds); var customerTags = _corporateCustomerCustomTagRepository.GetByCustomerIds(customerIds); var eventIds = calls.Where(x => x.EventId > 0).Select(x => x.EventId); var events = _eventRepository.GetEventswithPodbyIds(eventIds); var organisationRoleIds = calls.Select(c => c.CreatedByOrgRoleUserId).ToArray(); var callIds = calls.Select(c => c.Id).ToArray(); EventBasicInfoListModel eventBasicInfoListModel = null; List <EventCustomer> eventCusomters = null; List <Appointment> appointments = null; IEnumerable <OrderedPair <long, string> > registeredbyAgentNameIdPair = null; if (events != null) { eventBasicInfoListModel = _eventBasicInfoListHelper.EventBasicInfoListForCallQueue(events); } if (events != null && !customerIds.IsNullOrEmpty()) { eventCusomters = _eventCustomerRepository.GetByCustomerIds(customerIds).Where(s => eventIds.Contains(s.EventId)).ToList(); } if (!eventCusomters.IsNullOrEmpty()) { var appointmentIds = eventCusomters.Where(x => x.AppointmentId.HasValue).Select(x => x.AppointmentId.Value); appointments = _appointmentRepository.GetByIds(appointmentIds).ToList(); } if (organisationRoleIds != null && !organisationRoleIds.IsNullOrEmpty()) { registeredbyAgentNameIdPair = _organizationRoleUserRepository.GetNameIdPairofUsers(organisationRoleIds).ToArray(); } var dispositionNotes = _callCenterNotesRepository.GetByCallIds(callIds.ToArray()); var orderedPairsCustomersShippingDetails = _shippingDetailRepository.GetShippingDetailsIdCustomerId(customerIds); var customersShippingDetails = _shippingDetailRepository.GetShippingDetailsForCustomerIds(customerIds); var customerShippingAddressIds = customersShippingDetails.Select(x => x.ShippingAddress.Id).ToList(); var customerAddress = _addressRepository.GetAddresses(customerShippingAddressIds); return(_outreachCallReportListModelFactory.CreateHourlyModel(customers, customerTags, calls, eventCusomters, eventBasicInfoListModel, appointments, registeredbyAgentNameIdPair, dispositionNotes, orderedPairsCustomersShippingDetails, customersShippingDetails, customerAddress, callQueues, customerEligibilities)); }