public CustomerOrderDetail GetCustomerOrderDetails(long customerId, long eventId)
        {
            var order           = _orderRepository.GetOrder(customerId, eventId);
            var customerProfile = _customerRepository.GetCustomer(customerId);

            if (customerProfile == null)
            {
                return(null);
            }

            var eventPackages = _eventPackageRepository.GetPackagesForEvent(eventId);
            var eventTests    = _eventTestRepository.GetTestsForEvent(eventId);

            var customerOrder = new CustomerOrderDetail
            {
                OrderId    = order.Id,
                EventId    = eventId,
                CustomerId = customerId
            };

            var orderPackage = order.OrderDetails.FirstOrDefault(o => o.DetailType == OrderItemType.EventPackageItem && o.OrderItemStatus.OrderStatusState == OrderStatusState.FinalSuccess);

            if (orderPackage != null)
            {
                var eventPackage = eventPackages.SingleOrDefault(x => x.Id == orderPackage.OrderItem.ItemId);
                customerOrder.PackageModel = GetEventPackage(eventPackage);
            }


            var orderTests = order.OrderDetails.Where(o => o.DetailType == OrderItemType.EventTestItem && o.OrderItemStatus.OrderStatusState == OrderStatusState.FinalSuccess).ToList();

            if (orderTests != null)
            {
                var testIds   = orderTests.Select(s => s.OrderItem.ItemId).ToArray();
                var evemtTest = eventTests.Where(et => testIds.Contains(et.Id));
                customerOrder.AlaCarteTests = GetTestModels(evemtTest);
            }

            var product = order.OrderDetails.Where(od => od.OrderItemStatus.OrderStatusState == OrderStatusState.FinalSuccess && od.OrderItem.OrderItemType == OrderItemType.ProductItem).Select(od => od.OrderItem.ItemId).FirstOrDefault();

            customerOrder.ProductId = product;

            var shippingDetailIds = order.OrderDetails.SelectMany(od => od.ShippingDetailOrderDetails.Where(sdod => sdod.IsActive).Select(sdod => sdod.ShippingDetailId)).ToArray();

            if (shippingDetailIds.Any())
            {
                var shipingDetails = _shippingDetailRepository.GetByIds(shippingDetailIds).ToList();
                customerOrder.ShippingOptions = shipingDetails.Select(x => new ShippingOptionDetail {
                    Id = x.Id
                }).ToArray();
            }

            return(customerOrder);
        }
예제 #2
0
        public ListModelBase <HourlyAppointmentBookedModel, HourlyAppointmentsBookedListModelFilter> GetHourlyAppointmentsBooked(int pageNumber, int pageSize, ModelFilterBase filter, out int totalRecords)
        {
            var customFilter = filter as HourlyAppointmentsBookedListModelFilter;

            customFilter = customFilter ?? new HourlyAppointmentsBookedListModelFilter();

            var appFilter = new AppointmentsBookedListModelFilter
            {
                AccountId = customFilter.AccountId,
                FromDate  = customFilter.FromDate,
                ToDate    = customFilter.ToDate,
                ShowCustomersWithAppointment = customFilter.ShowCustomersWithAppointment,
                IsHealthPlanEvent            = true
            };

            var eventCustomers = _eventCustomerRepository.GetEventCustomersbyRegisterationDate(pageNumber, pageSize, appFilter, out totalRecords);

            if (eventCustomers.IsNullOrEmpty())
            {
                return(null);
            }

            var appointments = _appointmentRepository.GetByIds(eventCustomers.Where(ec => ec.AppointmentId.HasValue).Select(ec => ec.AppointmentId.Value).ToList());
            var eventIds     = eventCustomers.Select(ec => ec.EventId).Distinct().ToArray();
            var model        = _eventReportingService.GetEventVolumeModel(eventCustomers.Select(ec => ec.EventId).Distinct().ToArray());

            var customers             = _customerRepository.GetCustomers(eventCustomers.Select(ec => ec.CustomerId).Distinct().ToArray());
            var customerIds           = customers.Select(x => x.CustomerId);
            var orders                = _orderRepository.GetAllOrdersByEventCustomerIds(eventCustomers.Select(ec => ec.Id).ToArray(), true);
            var customerEligibilities = _customerEligibilityRepository.GetCustomerEligibilityByCustomerIdsAndYear(customerIds, DateTime.Today.Year);

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

            var eventPackages = _eventPackageRepository.GetbyEventIds(eventIds);
            var eventTests    = _eventTestRepository.GetByEventIds(eventIds);

            var sourceCodes = _sourceCodeRepository.GetSourceCodeByIds(orders.SelectMany(o => o.OrderDetails.Where(od => od.SourceCodeOrderDetail != null && od.SourceCodeOrderDetail.IsActive)
                                                                                         .Select(od => od.SourceCodeOrderDetail.SourceCodeId)).Distinct().ToArray());

            var orgRoleUserIds = eventCustomers.Where(ec => ec.DataRecorderMetaData != null && ec.DataRecorderMetaData.DataRecorderCreator != null).Select(ec => ec.DataRecorderMetaData.DataRecorderCreator.Id).ToList();

            var eventAppointmentChangeLogs = _eventAppointmentChangeLogRepository.GetByEventCustomerIds(eventCustomers.Select(ec => ec.Id).ToArray()).ToArray();

            orgRoleUserIds.AddRange(eventAppointmentChangeLogs.Select(eacl => eacl.CreatedByOrgRoleUserId));

            var registeredbyAgent = _organizationRoleUserRepository.GetOrganizationRoleUsers(orgRoleUserIds);

            var roles = _roleRepository.GetAll();

            var registeredbyAgentNameIdPair = _organizationRoleUserRepository.GetNameIdPairofUsers(orgRoleUserIds.ToArray()).ToArray();

            var callDetails = _callCenterCallRepository.GetCallDetails(customers);

            var shippingDetailIds = orders.SelectMany(o => o.OrderDetails.SelectMany(od => od.ShippingDetailOrderDetails.Select(sdod => sdod.ShippingDetailId))).ToArray();
            var shippingDetails   = _shippingDetailRepository.GetByIds(shippingDetailIds);
            var cdShippingOption  = _shippingOptionRepository.GetShippingOptionByProductId((long)Product.UltraSoundImages);
            var shippingOptions   = _shippingOptionRepository.GetAllShippingOptions();

            var customTags = _customTagRepository.GetByCustomerIds(customerIds);

            var tagNames               = customers.Where(x => !string.IsNullOrEmpty(x.Tag)).Select(x => x.Tag).ToArray();
            var corporateAccount       = _corporateAccountRepository.GetByTags(tagNames);
            var corporateAccountIds    = corporateAccount.Select(x => x.Id).ToArray();
            var accountAdditionalField = _accountAdditionalFieldRepository.GetAccountAdditionalFieldsByAccountIds(corporateAccountIds);

            var primaryCarePhysicians = _primaryCarePhysicianRepository.GetByCustomerIds(eventCustomers.Select(ec => ec.CustomerId).Distinct().ToArray());
            var languages             = _languageRepository.GetAll();
            var pcpAppointments       = _pcpAppointmentRepository.GetByEventCustomerIds(eventCustomers.Select(ec => ec.Id).ToArray());

            return(_customAppointmentsBookedModelFactory.CreateHourlyModel(eventCustomers, appointments, orders, model, customers, registeredbyAgent, roles, registeredbyAgentNameIdPair, sourceCodes, callDetails,
                                                                           shippingDetails, cdShippingOption, shippingOptions, eventAppointmentChangeLogs, primaryCarePhysicians, eventPackages, eventTests, languages, customTags, corporateAccount,
                                                                           accountAdditionalField, pcpAppointments, customerEligibilities));
        }