public ListModelBase <AppointmentEncounterModel, AppointmentEncounterFilter> GetAppointmentEncounterReport(int pageNumber, int pageSize, ModelFilterBase filter, out int totalRecords) { var eventCustomers = _eventCustomerRepository.GetAppointmentEncounterReport(pageNumber, pageSize, filter as AppointmentEncounterFilter, out totalRecords); if (eventCustomers.IsNullOrEmpty()) { return(null); } var customerids = eventCustomers.Select(x => x.CustomerId).Distinct().ToArray(); var eventCustomerIds = eventCustomers.Select(x => x.Id).ToArray(); var appointmentIds = eventCustomers.Where(x => x.AppointmentId.HasValue).Select(x => x.AppointmentId.Value); var eventIds = eventCustomers.Select(x => x.EventId).Distinct().ToArray(); var customers = _customerRepository.GetCustomers(customerids); var eventsCollection = ((IUniqueItemRepository <Event>)_eventRepository).GetByIds(eventIds); var pcpAppointment = _pcpAppointmentRepository.GetByEventCustomerIds(eventCustomerIds); var appointments = _appointmentRepository.GetByIds(appointmentIds); return(_appointmentEncounterFactory.Create(eventCustomers, customers, pcpAppointment, appointments, eventsCollection)); }