Пример #1
0
        public PackageSelectionViewData GetPackageSelectionViewData(long eventId, long roleId, long packageId,
                                                                    List <long> packageTestIds, List <long> independentTestIds)
        {
            var eventPackages = _eventPackageRepository.GetPackagesForEventByRole(eventId, roleId).ToList();
            var packages      = eventPackages.Select(ep => ep.Package).ToList();

            var currentSelectedPackage = packages.SingleOrDefault(p => p.Id == packageId);

            var eventTests = _eventTestRepository.GetTestsForEventByRole(eventId, roleId);
            var tests      = eventTests.Select(et => et.Test).ToList();

            tests = AdjustAndSortTests(tests);

            if (!packageTestIds.IsNullOrEmpty() || !independentTestIds.IsNullOrEmpty())
            {
                var selectedPackageId = _shoppingCartRecommendationService.RecommendPackage(packageId, packageTestIds,
                                                                                            independentTestIds, packages);
                var selectedPackage = packages.SingleOrDefault(p => p.Id == selectedPackageId);

                var packageSelectionViewData = _packageSelectionViewDataFactory.Create(selectedPackageId, packageTestIds, independentTestIds, packages, tests);

                packageSelectionViewData.RecommendationMessage =
                    _shoppingCartRecommendationService.RecommendPackageUpgrade(packageSelectionViewData, packages);

                if (selectedPackageId != packageId)
                {
                    if (selectedPackageId > 0 && packageId > 0 && (selectedPackage != null && currentSelectedPackage != null && selectedPackage.Price > currentSelectedPackage.Price))
                    {
                        packageSelectionViewData.PackageChangeMessage = string.Format(
                            "We have changed your package from {0} to {1}. This Package will save you ${2} for the same set of test(s).",
                            currentSelectedPackage.Name, selectedPackage.Name, packageSelectionViewData.TotalSavings);
                    }
                    if (selectedPackageId > 0 && packageId == 0 && selectedPackage != null)
                    {
                        packageSelectionViewData.PackageChangeMessage = string.Format(
                            "We have changed your package to {0}. This Package will save you ${1} for the same set of test(s).",
                            selectedPackage.Name, packageSelectionViewData.TotalSavings);
                    }
                }
                return(packageSelectionViewData);
            }
            return(_packageSelectionViewDataFactory.Create(packageId, packageTestIds, independentTestIds, packages, tests));
        }
Пример #2
0
        public void GetbyEventidAndRole_ValidId_Tester()
        {
            var eventPackages = _eventPackageRepository.GetPackagesForEventByRole(24759, 8);

            Assert.IsNotNull(eventPackages);
            Assert.IsNotEmpty(eventPackages.ToArray());

            var eventPackageIds = eventPackages.Select(ep => ep.Id).ToArray();
            var packageIds      = eventPackages.Select(ep => ep.PackageId).ToArray();
            var eventIds        = eventPackages.Select(ep => ep.EventId).ToArray();

            Assert.IsTrue(eventPackageIds.Contains(73563));
            Assert.IsTrue(eventPackageIds.Contains(73562));

            Assert.IsTrue(packageIds.Contains(124));
            Assert.IsTrue(packageIds.Contains(107));

            Assert.IsTrue(eventIds.Contains(24759));
        }
        public OrderPlaceEditModel GetEventPackage(OrderPlaceEditModel model, long eventId, Roles role, long customerId, TempCart tempCart)
        {
            var theEvent       = _eventRepository.GetById(eventId);
            var userGender     = !string.IsNullOrEmpty(tempCart.Gender) ? ((long)(Gender)Enum.Parse(typeof(Gender), tempCart.Gender, true)) : (long)Gender.Unspecified;
            var enableAlaCarte = Convert.ToBoolean(_configurationRepository.GetConfigurationValue(ConfigurationSettingName.EnableAlaCarte));

            var parentRole = (Roles)GetParentRoleIdByRoleId((long)role);

            if (enableAlaCarte)
            {
                if (role == Roles.Customer || parentRole == Roles.Customer)
                {
                    enableAlaCarte = theEvent.EnableAlaCarteOnline;
                }
                else if (role == Roles.CallCenterRep || role == Roles.CallCenterManager || parentRole == Roles.CallCenterRep || parentRole == Roles.CallCenterManager)
                {
                    enableAlaCarte = theEvent.EnableAlaCarteCallCenter;
                }
                else if (role == Roles.Technician || parentRole == Roles.Technician)
                {
                    enableAlaCarte = theEvent.EnableAlaCarteTechnician;
                }
                else if (!(theEvent.EnableAlaCarteOnline || theEvent.EnableAlaCarteCallCenter || theEvent.EnableAlaCarteTechnician))
                {
                    enableAlaCarte = false;
                }
            }

            var eventPackages = _eventPackageRepository.GetPackagesForEventByRole(eventId, (long)role, userGender);

            var eventTests = enableAlaCarte ? _eventTestRepository.GetTestsForEventByRole(eventId, (long)role, userGender) : null;

            if (eventTests != null && eventTests.Count() > 0)
            {
                eventTests = eventTests.Where(et => et.Test.ShowInAlaCarte).Select(et => et).ToArray();
            }
            var products        = _productRepository.GetAllProductsForEvent(eventId);
            var shippingOptions = _shippingOptionRepository.GetAllShippingOptionsForBuyingProcess();

            var shippingOptionsToBind = new List <ShippingOption>();

            if (theEvent.EventType == EventType.Retail)
            {
                var onlineShippingOption = _shippingOptionRepository.GetOnlineShippingOption();
                shippingOptionsToBind.Add(onlineShippingOption);

                if (shippingOptions != null && shippingOptions.Count > 0)
                {
                    shippingOptions.RemoveAll(so => so.Price == 0);
                    shippingOptionsToBind.AddRange(shippingOptions);
                }
                model.EventType = EventType.Retail;
            }
            else if (theEvent.EventType == EventType.Corporate)
            {
                var onlineShippingOption = _shippingOptionRepository.GetOnlineShippingOption();
                shippingOptionsToBind.Add(onlineShippingOption);

                shippingOptions = _shippingOptionRepository.GetAllShippingOptionForCorporate(theEvent.AccountId.HasValue ? theEvent.AccountId.Value : 0);
                if (shippingOptions != null && shippingOptions.Count > 0)
                {
                    shippingOptionsToBind.AddRange(shippingOptions);
                }
                else
                {
                    tempCart.ShippingId = onlineShippingOption.Id;
                }

                model.EventType = EventType.Corporate;
            }

            if (theEvent.EventType == EventType.Corporate)
            {
                eventPackages = eventPackages != null?eventPackages.OrderByDescending(d => d.Price).ThenBy(d => d.Package.RelativeOrder) : null;
            }
            else
            {
                eventPackages = eventPackages != null?eventPackages.OrderByDescending(d => d.Price) : null;
            }

            eventTests = eventTests != null?eventTests.OrderByDescending(d => d.Price) : null;

            products = products != null?products.OrderBy(d => d.Price).ToList() : null;


            model.AllEventPackages   = Mapper.Map <IEnumerable <EventPackage>, IEnumerable <EventPackageOrderItemViewModel> >(eventPackages);
            model.AllEventTests      = Mapper.Map <IEnumerable <EventTest>, IEnumerable <EventTestOrderItemViewModel> >(eventTests);
            model.AllProducts        = Mapper.Map <IEnumerable <ElectronicProduct>, IEnumerable <ProductOrderItemViewModel> >(products);
            model.AllShippingOptions = Mapper.Map <IEnumerable <ShippingOption>, IEnumerable <ShippingOptionOrderItemViewModel> >(shippingOptionsToBind);

            int age = 0;

            if (customerId > 0)
            {
                var customer = _customerRepository.GetCustomer(customerId);
                age = customer.DateOfBirth.HasValue ? customer.DateOfBirth.Value.GetAge() : 0;
            }
            else if (tempCart.Dob.HasValue)
            {
                age = tempCart.Dob.Value.GetAge();
            }

            if (age > 0)
            {
                foreach (var eventPackage in model.AllEventPackages)
                {
                    foreach (var test in eventPackage.Tests)
                    {
                        if (test.MinAge > 0 && age < test.MinAge)
                        {
                            eventPackage.NotAvailable           = true;
                            eventPackage.NotAvailabilityMessage = "includes " + test.Name + " for which minimum age required is " + test.MinAge;
                            break;
                        }
                        if (test.MaxAge > 0 && age > test.MaxAge)
                        {
                            eventPackage.NotAvailable           = true;
                            eventPackage.NotAvailabilityMessage = "includes " + test.Name + " for which maximum age required is " + test.MaxAge;
                            break;
                        }
                    }
                }

                foreach (var test in model.AllEventTests)
                {
                    if (test.MinAge > 0 && age < test.MinAge)
                    {
                        test.NotAvailable           = true;
                        test.NotAvailabilityMessage = "For this test minimum age required is " + test.MinAge;
                        break;
                    }
                    if (test.MaxAge > 0 && age > test.MaxAge)
                    {
                        test.NotAvailable           = true;
                        test.NotAvailabilityMessage = "For this test maximum age required is " + test.MaxAge;
                        break;
                    }
                }
            }

            if (model.AllEventPackages != null && model.AllEventPackages.Any())
            {
                EventPackageOrderItemViewModel package = null;
                Gender gender;
                Enum.TryParse(tempCart.Gender, out gender);

                package = EventPackageOrderItemViewModel(model.AllEventPackages, eventPackages, gender);

                foreach (var eventPackage in model.AllEventPackages)
                {
                    eventPackage.IsRecommended = eventPackage.PackageId == package.PackageId;
                }
            }

            LoadPackageImagePath(eventPackages, model.AllEventPackages);

            model.EnableImageUpsell = IsImageUpsellEnabled(eventId);

            return(model);
        }
        private IEnumerable <PackageModel> GetAvilablePackages(long eventId)
        {
            var avilablePackages = _eventPackageRepository.GetPackagesForEventByRole(eventId, (long)Roles.Technician);

            return(avilablePackages.Select(ep => GetEventPackage(ep)));
        }
Пример #5
0
        public OrderPlaceEditModel GetEventPackageList(TempCart tempCart)
        {
            var model = new OrderPlaceEditModel();

            var userGender = !string.IsNullOrEmpty(tempCart.Gender) ? ((long)(Gender)Enum.Parse(typeof(Gender), tempCart.Gender, true)) : (long)Gender.Unspecified;

            if (tempCart.EventId != null)
            {
                var theEvent = _eventRepository.GetById(tempCart.EventId.Value);

                model.RecommendPackageForEvent = theEvent.RecommendPackage;

                var eventPackages = _eventPackageRepository.GetPackagesForEventByRole(tempCart.EventId.Value, (long)Roles.Customer, userGender);
                if (theEvent.EventType == EventType.Corporate)
                {
                    eventPackages = eventPackages != null
                        ? eventPackages.OrderByDescending(d => d.Price).ThenBy(d => d.Package.RelativeOrder)
                        : null;
                }
                else
                {
                    eventPackages = eventPackages != null?eventPackages.OrderByDescending(d => d.Price) : null;
                }

                model.AllEventPackages =
                    Mapper.Map <IEnumerable <EventPackage>, IEnumerable <EventPackageOrderItemViewModel> >(eventPackages);


                var age = 0;
                if (tempCart.Dob.HasValue)
                {
                    age = tempCart.Dob.Value.GetAge();
                }

                if (age > 0)
                {
                    foreach (var eventPackage in model.AllEventPackages)
                    {
                        foreach (var test in eventPackage.Tests)
                        {
                            if (test.MinAge > 0 && age < test.MinAge)
                            {
                                eventPackage.NotAvailable           = true;
                                eventPackage.NotAvailabilityMessage = "includes " + test.Name +
                                                                      " for which minimum age required is " +
                                                                      test.MinAge;
                                break;
                            }
                            if (test.MaxAge > 0 && age > test.MaxAge)
                            {
                                eventPackage.NotAvailable           = true;
                                eventPackage.NotAvailabilityMessage = "includes " + test.Name +
                                                                      " for which maximum age required is " +
                                                                      test.MaxAge;
                                break;
                            }
                        }
                    }
                }

                if (model.AllEventPackages != null && model.AllEventPackages.Any())
                {
                    EventPackageOrderItemViewModel package = null;
                    Gender gender;
                    Enum.TryParse(tempCart.Gender, out gender);

                    package = EventPackageOrderItemViewModel(model.AllEventPackages, eventPackages, gender);

                    foreach (var eventPackage in model.AllEventPackages)
                    {
                        eventPackage.IsRecommended = package != null && eventPackage.PackageId == package.PackageId;
                    }

                    int sequence = 1;
                    //if (tempCart.EventPackageId > 0)
                    //{
                    //    var selectedPackage = model.AllEventPackages.Where(ep => ep.EventPackageId == tempCart.EventPackageId);
                    //    if (selectedPackage.Any())
                    //    {
                    //        selectedPackage.First().DisplaySequence = sequence;
                    //        sequence = sequence + 1;
                    //    }
                    //}

                    var bestValuePackage = model.AllEventPackages.Where(ep => ep.BestValue);

                    //if (tempCart.EventPackageId > 0)
                    //{
                    //    bestValuePackage = model.AllEventPackages.Where(ep => ep.BestValue && ep.EventPackageId != tempCart.EventPackageId);
                    //}

                    if (bestValuePackage.Any())
                    {
                        bestValuePackage.First().DisplaySequence = sequence;
                        sequence = sequence + 1;
                    }

                    var mostPopularPackage = model.AllEventPackages.Where(ep => ep.MostPopular);

                    //if (tempCart.EventPackageId > 0)
                    //{
                    //    mostPopularPackage = model.AllEventPackages.Where(ep => ep.MostPopular && ep.EventPackageId != tempCart.EventPackageId);
                    //}

                    if (mostPopularPackage.Any())
                    {
                        mostPopularPackage.First().DisplaySequence = sequence;
                        sequence = sequence + 1;
                    }

                    //var lowestpricePackage = model.AllEventPackages.OrderBy(s => s.Price).First();
                    //if (lowestpricePackage != null)
                    //{
                    //    lowestpricePackage.IsLowestPrice = true;
                    //    lowestpricePackage.DisplaySequence = sequence;
                    //    sequence = sequence + 1;
                    //}

                    var highestpricePackage = model.AllEventPackages.OrderByDescending(s => s.Price).First();
                    if (highestpricePackage != null)
                    {
                        highestpricePackage.IsHighestPrice = true;
                    }

                    foreach (var packageItem in model.AllEventPackages.OrderByDescending(s => s.Price).Where(x => x.IsLowestPrice == false && x.MostPopular == false && x.BestValue == false)) //&& (!(tempCart.EventPackageId > 0) || x.EventPackageId != tempCart.EventPackageId)
                    {
                        packageItem.DisplaySequence = sequence;
                        sequence = sequence + 1;
                    }

                    model.AllEventPackages = model.AllEventPackages.OrderBy(d => d.DisplaySequence);
                }

                _eventPackageSelectorService.LoadPackageImagePath(eventPackages, model.AllEventPackages);
            }

            return(UpdatePanelTests(model));
        }