public ListModelBase <InterviewInboundViewModel, InterviewInboundFilter> GetInterviewInboundReportList(int pageNumber, int pageSize, ModelFilterBase filter, out int totalRecords) { filter = filter ?? new InterviewInboundFilter(); var interviewInboundFilter = filter as InterviewInboundFilter ?? new InterviewInboundFilter(); var responseVendorReportFilter = new ResponseVendorReportFilter { StartDate = interviewInboundFilter.StartDate, EndDate = interviewInboundFilter.EndDate, AccountId = interviewInboundFilter.AccountId, CustomTags = interviewInboundFilter.CustomTags }; var customerIds = _customerRepository.GetCustomersByCustomTag(responseVendorReportFilter, pageNumber, pageSize, out totalRecords); //var customerIds = _callRepository.GetForInterviewReport(filter as InterviewInboundFilter, pageNumber, pageSize, out totalRecords); if (customerIds.IsNullOrEmpty()) { return(null); } var calls = _callRepository.GetCallsForInterviewReport(filter as InterviewInboundFilter, customerIds); var customers = customerIds.Any() ? _customerRepository.GetCustomers(customerIds.ToArray()) : new List <Customer>(); //var eventCustomers = _eventCustomerRepository.GetEventCustomersByEventIdsCustomerIds(eventIds, customerIds) ?? new List<EventCustomer>(); var eventCustomers = _eventCustomerRepository.GetByEventIdsOrCustomerIds(interviewInboundFilter.StartDate, customerIds) ?? new List <EventCustomer>(); var eventCustomerIds = eventCustomers.Select(x => x.Id); var eventIds = eventCustomers.Select(x => x.EventId).ToArray(); var events = _eventRepository.GetEvents(eventIds); var chaseOutbounds = _chaseOutboundRepository.GetByCustomerIds(customerIds); var customerChaseCampaigns = _chaseCampaignRepository.GetCustomerChaseCampaignsByCustomerIds(customerIds.ToArray()); var chaseCampaignIds = customerChaseCampaigns.Select(x => x.ChaseCampaignId).Distinct(); var chaseCampaigns = _chaseCampaignRepository.GetByIds(chaseCampaignIds); var appointmentIds = eventCustomers.Where(x => x.AppointmentId.HasValue).Select(x => x.AppointmentId.Value); var appointments = _appointmentRepository.GetByIds(appointmentIds); var eventAppointmentCancellatonLogs = _eventAppointmentCancellationLogRepository.GetByEventCustomerIds(eventCustomerIds); var noteIds = eventAppointmentCancellatonLogs.Where(x => x.NoteId.HasValue).Select(x => x.NoteId.Value); var customerCallNotes = _customerCallNotesRepository.GetByIds(noteIds); var eventIdStaffIdPairs = _eventRepository.GetEventStaffPairs(eventIds); var orgRoleUserIds = eventIdStaffIdPairs.Select(x => x.SecondValue).Distinct().ToArray(); var organizationRoleUsers = _organizationRoleUserRepository.GetOrganizationRoleUsers(orgRoleUserIds); var userIds = organizationRoleUsers.Select(x => x.UserId).Distinct().ToList(); var users = _userRepository.GetUsers(userIds); return(_interviewInboundReportFactory.Create(eventCustomers, customers, chaseOutbounds, customerChaseCampaigns, chaseCampaigns, calls, appointments, events, eventAppointmentCancellatonLogs, customerCallNotes, eventIdStaffIdPairs, organizationRoleUsers, users)); }