public ListModelBase <DailyPatientRecapCustomModel, DailyPatientRecapModelFilter> GetDailyPatientReapCustomModel(int pageNumber, int pageSize, ModelFilterBase filter, out int totalRecords) { var eventCustomers = _eventCustomerRepository.GetEventsCustomersForDailyPatientRecapCustom(pageNumber, pageSize, filter as DailyPatientRecapModelFilter, out totalRecords); if (eventCustomers.IsNullOrEmpty()) { return(null); } var eventIds = eventCustomers.Select(x => x.EventId).Distinct(); var events = _eventRepository.GetEventswithPodbyIds(eventIds); var pods = _podRepository.GetPodsForEvents(eventIds); var eventPods = _eventPodRepository.GetByEventIds(eventIds); var customerIds = eventCustomers.Select(x => x.CustomerId).Distinct().ToArray(); var customers = _customerRepository.GetCustomers(customerIds); var eventCustomerIds = eventCustomers.Select(x => x.Id).ToArray(); var orders = _orderRepository.GetAllOrdersByEventCustomerIds(eventCustomerIds, true); var orderPackageIdNamePair = _eventPackageRepository.GetPackageNamesForOrder(orders.Select(o => o.Id).ToList()); //var orderTestIdNamePair = _eventTestRepository.GetTestNamesForOrders(orders.Select(o => o.Id).ToList()); var orderIdEventPackageTestIdPairs = _eventPackageRepository.GetOrderIdEventPackageTestIdPairsForOrder(orders.Select(o => o.Id).ToArray()); var orderIdTestIdPairs = _eventTestRepository.GetOrderIdTestIdPairsForOrders(orders.Select(o => o.Id).ToArray()); var testNotPerformedEventCustomerIdTestIdPairs = _testNotPerformedRepository.GetEventCusromerResultIdTestIdPairs(eventCustomerIds); var testIds = orderIdEventPackageTestIdPairs.Select(op => op.SecondValue).Distinct().ToList(); testIds.AddRange(orderIdTestIdPairs.Select(op => op.SecondValue).Distinct().ToArray()); var tests = _testRepository.GetTestNameValuePair(testIds); var eventIdCorporateAccounrNamePairs = _corporateAccountRepository.GetEventIdCorporateAccountNamePair(eventIds); return(_dailyPatientRecapListModelFactory.CreateCustomListModel(eventCustomers, customers, orders, eventIdCorporateAccounrNamePairs, pods, eventPods, events, orderIdEventPackageTestIdPairs, orderIdTestIdPairs, testNotPerformedEventCustomerIdTestIdPairs, tests, orderPackageIdNamePair)); }