Example #1
0
        public ListModelBase <CallCenterCallReportModel, CallCenterCallReportModelFilter> GetCallCenterCallReport(int pageNumber, int pageSize, ModelFilterBase filter, out int totalRecords)
        {
            var calls = _callCenterCallRepository.GetCallCenterCallQueueCustomer(filter as CallCenterCallReportModelFilter, pageNumber, pageSize, out totalRecords);

            if (calls == null || !calls.Any())
            {
                return(null);
            }

            var customerIds = calls.Select(c => c.CalledCustomerId).ToArray();

            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);

            var customerEligibilities = _customerEligibilityRepository.GetCustomerEligibilityByCustomerIdsAndYear(customerIds, DateTime.Today.Year);

            if (customerEligibilities.IsNullOrEmpty())
            {
                customerEligibilities = new List <CustomerEligibility>();
            }

            return(_callCenterCallReportListModelFactory.Create(customers, customerTags, calls, eventCusomters, eventBasicInfoListModel, appointments, registeredbyAgentNameIdPair, dispositionNotes, orderedPairsCustomersShippingDetails,
                                                                customersShippingDetails, customerAddress, callQueues, customerEligibilities));
        }