Beispiel #1
0
        /// <summary>
        /// Creates view model for checkout preview step.
        /// </summary>
        /// <param name="paymentMethod">Payment method selected on preview step</param>
        public PreviewViewModel PreparePreviewViewModel(PaymentMethodViewModel paymentMethod = null)
        {
            var cart           = mShoppingService.GetCurrentShoppingCart();
            var billingAddress = mShoppingService.GetBillingAddress();
            var shippingOption = cart.ShippingOption;
            var paymentMethods = CreatePaymentMethodList(cart);

            paymentMethod = paymentMethod ?? new PaymentMethodViewModel(cart.PaymentOption, paymentMethods);

            // PaymentMethods are excluded from automatic binding and must be recreated manually after post action
            paymentMethod.PaymentMethods = paymentMethod.PaymentMethods ?? paymentMethods;

            var deliveryDetailsModel = new DeliveryDetailsViewModel
            {
                Customer       = new CustomerViewModel(cart.Customer),
                BillingAddress = new BillingAddressViewModel(billingAddress, null, mCountryRepository),
                ShippingOption = new ShippingOptionViewModel(shippingOption, null, cart.IsShippingNeeded)
            };

            var cartModel = new CartViewModel(cart);

            var viewModel = new PreviewViewModel
            {
                CartModel       = cartModel,
                DeliveryDetails = deliveryDetailsModel,
                ShippingName    = shippingOption?.ShippingOptionDisplayName ?? "",
                PaymentMethod   = paymentMethod
            };

            return(viewModel);
        }
        //EndDocSection:CouponCodeRemove


        //DocSection:DisplayDelivery
        /// <summary>
        /// Displays the customer details checkout process step.
        /// </summary>
        public ActionResult DeliveryDetails()
        {
            // Gets the current user's shopping cart
            ShoppingCartInfo cart = shoppingService.GetCurrentShoppingCart();

            // If the shopping cart is empty, displays the shopping cart
            if (cart.IsEmpty)
            {
                return(RedirectToAction(nameof(CheckoutController.ShoppingCart)));
            }

            // Gets all countries for the country selector
            SelectList countries = new SelectList(CountryInfoProvider.GetCountries(), "CountryID", "CountryDisplayName");

            // Creates a collection of shipping options enabled for the current site
            SelectList shippingOptions = CreateShippingOptionList(cart);

            // Loads the customer details
            DeliveryDetailsViewModel model = new DeliveryDetailsViewModel
            {
                Customer       = new CustomerViewModel(shoppingService.GetCurrentCustomer()),
                BillingAddress = new BillingAddressViewModel(shoppingService.GetBillingAddress(), countries, null),
                ShippingOption = new ShippingOptionViewModel(ShippingOptionInfoProvider.GetShippingOptionInfo(shoppingService.GetShippingOption()), shippingOptions)
            };

            // Displays the customer details step
            return(View(model));
        }
Beispiel #3
0
        /// <summary>
        /// Creates view model for checkout delivery step.
        /// </summary>
        /// <param name="customer">Filled customer details</param>
        /// <param name="billingAddress">Filled billing address</param>
        /// <param name="shippingOption">Selected shipping option</param>
        public DeliveryDetailsViewModel PrepareDeliveryDetailsViewModel(CustomerViewModel customer = null, BillingAddressViewModel billingAddress = null, ShippingOptionViewModel shippingOption = null)
        {
            var cart            = mShoppingService.GetCurrentShoppingCart();
            var countries       = CreateCountryList();
            var shippingOptions = CreateShippingOptionList();

            customer = customer ?? new CustomerViewModel(cart.Customer);

            var addresses = (cart.Customer != null)
                ? mAddressRepository.GetByCustomerId(cart.Customer.CustomerID)
                : Enumerable.Empty <AddressInfo>();

            var billingAddresses = new SelectList(addresses, nameof(AddressInfo.AddressID), nameof(AddressInfo.AddressName));

            billingAddress = billingAddress ?? new BillingAddressViewModel(mShoppingService.GetBillingAddress(), countries, mCountryRepository, billingAddresses);
            shippingOption = shippingOption ?? new ShippingOptionViewModel(cart.ShippingOption, shippingOptions, cart.IsShippingNeeded);

            billingAddress.BillingAddressCountryStateSelector.Countries = billingAddress.BillingAddressCountryStateSelector.Countries ?? countries;
            billingAddress.BillingAddressSelector = billingAddress.BillingAddressSelector ?? new AddressSelectorViewModel {
                Addresses = billingAddresses
            };
            shippingOption.ShippingOptions = shippingOptions;

            var viewModel = new DeliveryDetailsViewModel
            {
                Customer       = customer,
                BillingAddress = billingAddress,
                ShippingOption = shippingOption
            };

            return(viewModel);
        }
Beispiel #4
0
        public ActionResult DeliveryDetails(DeliveryDetailsViewModel model)
        {
            // Gets the current user's shopping cart
            ShoppingCart cart = shoppingService.GetCurrentShoppingCart();

            // Gets all enabled shipping options for the shipping option selector
            SelectList shippingOptions = new SelectList(shippingOptionRepository.GetAllEnabled(), "ShippingOptionID", "ShippingOptionDisplayName");

            // If the ModelState is not valid, assembles the country list and the shipping option list and displays the step again
            if (!ModelState.IsValid)
            {
                SelectList countries = new SelectList(CountryInfoProvider.GetAllCountries(), "CountryID", "CountryDisplayName");
                model.BillingAddress.Countries       = countries;
                model.ShippingOption.ShippingOptions = new ShippingOptionModel(cart.ShippingOption, shippingOptions).ShippingOptions;
                return(View(model));
            }

            // Gets the shopping cart's customer and applies the customer details from the checkout process step
            if (cart.Customer == null)
            {
                cart.Customer = new Customer();
            }
            model.Customer.ApplyToCustomer(cart.Customer);

            // Gets the shopping cart's billing address and applies the billing address from the checkout process step
            cart.BillingAddress = addressRepository.GetById(model.BillingAddress.AddressID) ?? new CustomerAddress();
            model.BillingAddress.ApplyTo(cart.BillingAddress);

            // Sets the address personal name and saves the shopping cart
            cart.BillingAddress.PersonalName = $"{cart.Customer.FirstName} {cart.Customer.LastName}";
            cart.Save();

            // Redirects to the next step of the checkout process
            return(RedirectToAction("PreviewAndPay"));
        }
        //EndDocSection:CouponCode


        //DocSection:DisplayDelivery
        /// <summary>
        /// Displays the customer detail checkout process step without any additional functionality for registered customers.
        /// </summary>
        public ActionResult DeliveryDetails()
        {
            // Gets the current user's shopping cart
            ShoppingCart cart = shoppingService.GetCurrentShoppingCart();

            // If the shopping cart is empty, displays the shopping cart
            if (cart.IsEmpty)
            {
                return(RedirectToAction("ShoppingCart"));
            }

            // Gets all countries for the country selector
            SelectList countries = new SelectList(CountryInfoProvider.GetCountries(), "CountryID", "CountryDisplayName");

            // Gets all enabled shipping options for the shipping option selector
            SelectList shippingOptions = new SelectList(shippingOptionRepository.GetAllEnabled(), "ShippingOptionID", "ShippingOptionDisplayName");

            // Loads the customer details
            DeliveryDetailsViewModel model = new DeliveryDetailsViewModel
            {
                Customer       = new CustomerModel(cart.Customer),
                BillingAddress = new BillingAddressModel(cart.BillingAddress, countries, null),
                ShippingOption = new ShippingOptionModel(cart.ShippingOption, shippingOptions)
            };

            // Displays the customer details step
            return(View(model));
        }
Beispiel #6
0
        public IActionResult DeliveryDetails(DeliveryDetailsViewModel model)
        {
            // Gets the user's current shopping cart
            ShoppingCartInfo cart = shoppingService.GetCurrentShoppingCart();

            // Gets all enabled shipping options for the shipping option selector
            SelectList shippingOptions = new SelectList(
                shippingOption.GetBySite(
                    siteService.CurrentSite.SiteID, true).ToList(),
                "ShippingOptionID",
                "ShippingOptionDisplayName");

            // If the ModelState is not valid, assembles the country list and the shipping option list and displays the step again
            if (!ModelState.IsValid)
            {
                model.BillingAddress.Countries       = new SelectList(countryInfo.Get(), "CountryID", "CountryDisplayName");
                model.ShippingOption.ShippingOptions = new ShippingOptionViewModel(
                    shippingOption.Get(shoppingService.GetShippingOption()), shippingOptions).ShippingOptions;
                return(View(model));
            }

            // Gets the shopping cart's customer and applies the customer details from the checkout process step
            var customer = shoppingService.GetCurrentCustomer();

            if (customer == null)
            {
                UserInfo userInfo = cart.User;
                if (userInfo != null)
                {
                    customer = CustomerHelper.MapToCustomer(cart.User);
                }
                else
                {
                    customer = new CustomerInfo();
                }
            }
            model.Customer.ApplyToCustomer(customer);

            // Sets the updated customer object to the current shopping cart
            shoppingService.SetCustomer(customer);

            // Gets the shopping cart's billing address and applies the billing address from the checkout process step
            var address = addressInfo.Get(model.BillingAddress.AddressID) ?? new AddressInfo();

            model.BillingAddress.ApplyTo(address);

            // Sets the address personal name
            address.AddressPersonalName = $"{customer.CustomerFirstName} {customer.CustomerLastName}";

            // Saves the billing address
            shoppingService.SetBillingAddress(address);

            // Sets the selected shipping option and evaluates the cart
            shoppingService.SetShippingOption(model.ShippingOption.ShippingOptionID);

            // Redirects to the next step of the checkout process
            return(RedirectToAction(nameof(PreviewAndPay)));
        }
Beispiel #7
0
        public async Task <IActionResult> Details(string id)
        {
            DeliveryDetailsServiceModel deliveryDetailsServiceModel = await this.deliveryService.GetAll()
                                                                      .SingleOrDefaultAsync(receipt => receipt.Id == id);

            DeliveryDetailsViewModel deliverytDetailsViewModel = deliveryDetailsServiceModel.To <DeliveryDetailsViewModel>();

            return(this.View(deliverytDetailsViewModel));
        }
        public ActionResult DeliveryDetails(DeliveryDetailsViewModel model)
        {
            // Check the selected shipping option
            if (!mCheckoutService.IsShippingOptionValid(model.ShippingOption.ShippingOptionID))
            {
                ModelState.AddModelError("ShippingOption.ShippingOptionID", ResHelper.GetString("DancingGoatMvc.Shipping.ShippingOptionRequired"));
            }

            // Check if the billing address's country and state are valid
            var countryStateViewModel = model.BillingAddress.BillingAddressCountryStateSelector;

            if (!mCheckoutService.IsCountryValid(countryStateViewModel.CountryID))
            {
                countryStateViewModel.CountryID = 0;
                ModelState.AddModelError("BillingAddress.BillingAddressCountryStateSelector.CountryID", ResHelper.GetString("DancingGoatMvc.Address.CountryIsRequired"));
            }
            else if (!mCheckoutService.IsStateValid(countryStateViewModel.CountryID, countryStateViewModel.StateID))
            {
                countryStateViewModel.StateID = 0;
                ModelState.AddModelError("BillingAddress.BillingAddressCountryStateSelector.StateID", ResHelper.GetString("DancingGoatMvc.Address.StateIsRequired"));
            }

            if (!ModelState.IsValid)
            {
                var viewModel = mCheckoutService.PrepareDeliveryDetailsViewModel(model.Customer, model.BillingAddress, model.ShippingOption);
                return(View(viewModel));
            }

            var cart     = mShoppingService.GetCurrentShoppingCart();
            var customer = cart.Customer ?? new Customer();

            bool emailCanBeChanged = !User.Identity.IsAuthenticated || string.IsNullOrWhiteSpace(customer.Email);

            model.Customer.ApplyToCustomer(customer, emailCanBeChanged);
            cart.Customer = customer;

            var modelAddressID = model.BillingAddress.BillingAddressSelector?.AddressID ?? 0;
            var billingAddress = mCheckoutService.GetAddress(modelAddressID) ?? new CustomerAddress();

            model.BillingAddress.ApplyTo(billingAddress);
            billingAddress.PersonalName = $"{customer.FirstName} {customer.LastName}";

            cart.BillingAddress = billingAddress;
            cart.ShippingOption = mCheckoutService.GetShippingOption(model.ShippingOption.ShippingOptionID);

            cart.Evaluate();
            cart.Save();

            return(RedirectToAction("PreviewAndPay"));
        }
        public IActionResult DeliveryDetails(DeliveryDetailsViewModel vm)
        {
            if (ModelState.IsValid)
            {
                _checkoutService.SetAddressInSession(vm.Address);
                _checkoutService.SetPhoneNumberInSession(vm.PhoneNumber);

                return(RedirectToAction(nameof(OrderVerification)));
            }
            else
            {
                return(View());
            }
        }
        public async Task <IActionResult> DeliveryDetails()
        {
            DeliveryDetailsViewModel vm = new DeliveryDetailsViewModel();

            if (_signInManager.IsSignedIn(User))
            {
                ApplicationUser user = await _userManager.GetUserAsync(User);

                user.Address   = _context.Addresses.FirstOrDefault(x => x.AddressId == user.AddressId);
                vm.Address     = user.Address;
                vm.PhoneNumber = user.PhoneNumber;
            }

            return(View(vm));
        }
Beispiel #11
0
        public ActionResult DeliveryDetails(DeliveryDetailsViewModel model, [FromServices] IStringLocalizer <SharedResources> localizer)
        {
            // Check the selected shipping option
            bool isShippingNeeded = shoppingService.GetCurrentShoppingCart().IsShippingNeeded;

            if (isShippingNeeded && !checkoutService.IsShippingOptionValid(model.ShippingOption.ShippingOptionID))
            {
                ModelState.AddModelError("ShippingOption.ShippingOptionID", localizer["Please select a delivery method"]);
            }

            // Check if the billing address's country and state are valid
            var countryStateViewModel = model.BillingAddress.BillingAddressCountryStateSelector;

            if (!checkoutService.IsCountryValid(countryStateViewModel.CountryID))
            {
                countryStateViewModel.CountryID = 0;
                ModelState.AddModelError("BillingAddress.BillingAddressCountryStateSelector.CountryID", localizer["The Country field is required"]);
            }
            else if (!checkoutService.IsStateValid(countryStateViewModel.CountryID, countryStateViewModel.StateID))
            {
                countryStateViewModel.StateID = 0;
                ModelState.AddModelError("BillingAddress.BillingAddressCountryStateSelector.StateID", localizer["The State field is required"]);
            }

            if (!ModelState.IsValid)
            {
                var viewModel = checkoutService.PrepareDeliveryDetailsViewModel(model.Customer, model.BillingAddress, model.ShippingOption);

                return(View(viewModel));
            }

            var  customer          = GetCustomerOrCreateFromAuthenticatedUser() ?? new CustomerInfo();
            bool emailCanBeChanged = !User.Identity.IsAuthenticated || string.IsNullOrWhiteSpace(customer.CustomerEmail);

            model.Customer.ApplyToCustomer(customer, emailCanBeChanged);
            shoppingService.SetCustomer(customer);

            var modelAddressID = model.BillingAddress.BillingAddressSelector?.AddressID ?? 0;
            var billingAddress = checkoutService.GetAddress(modelAddressID) ?? new AddressInfo();

            model.BillingAddress.ApplyTo(billingAddress);
            billingAddress.AddressPersonalName = $"{customer.CustomerFirstName} {customer.CustomerLastName}";

            shoppingService.SetBillingAddress(billingAddress);
            shoppingService.SetShippingOption(model.ShippingOption?.ShippingOptionID ?? 0);

            return(RedirectToAction("PreviewAndPay"));
        }
        //EndDocSection:DisplayDelivery


        //DocSection:DisplayDeliveryAddressSelector
        /// <summary>
        /// Displays the customer details checkout process step with an address selector for known customers.
        /// </summary>
        public ActionResult DeliveryDetailsAddressSelector()
        {
            // Gets the current user's shopping cart
            ShoppingCartInfo cart = shoppingService.GetCurrentShoppingCart();

            // If the shopping cart is empty, redirects to the shopping cart view
            if (cart.IsEmpty)
            {
                return(RedirectToAction("ShoppingCart"));
            }

            // Gets all countries for the country selector
            SelectList countries = new SelectList(CountryInfoProvider.GetCountries(), "CountryID", "CountryDisplayName");

            // Gets the current customer
            CustomerInfo customer = shoppingService.GetCurrentCustomer();

            // Gets all customer billing addresses for the address selector
            IEnumerable <AddressInfo> customerAddresses = Enumerable.Empty <AddressInfo>();

            if (customer != null)
            {
                customerAddresses = AddressInfoProvider.GetAddresses(customer.CustomerID).ToList();
            }

            // Prepares address selector options
            SelectList addresses = new SelectList(customerAddresses, "AddressID", "AddressName");

            // Gets all enabled shipping options for the shipping option selector
            SelectList shippingOptions = new SelectList(ShippingOptionInfoProvider.GetShippingOptions(SiteContext.CurrentSiteID, true).ToList(), "ShippingOptionID", "ShippingOptionDisplayName");

            // Loads the customer details
            DeliveryDetailsViewModel model = new DeliveryDetailsViewModel
            {
                Customer       = new CustomerViewModel(shoppingService.GetCurrentCustomer()),
                BillingAddress = new BillingAddressViewModel(shoppingService.GetBillingAddress(), countries, addresses),
                ShippingOption = new ShippingOptionViewModel(ShippingOptionInfoProvider.GetShippingOptionInfo(shoppingService.GetShippingOption()), shippingOptions)
            };


            // Displays the customer details step
            return(View(model));
        }
        //EndDocSection:DisplayDelivery

        //DocSection:DisplayDeliveryAddressSelector
        /// <summary>
        /// Displays the customer detail checkout process step with an address selector for registered customers.
        /// </summary>
        public ActionResult DeliveryDetailsAddressSelector()
        {
            // Gets the current user's shopping cart
            ShoppingCart cart = shoppingService.GetCurrentShoppingCart();

            // If the shopping cart is empty, displays the shopping cart
            if (cart.IsEmpty)
            {
                return(RedirectToAction("ShoppingCart"));
            }

            // Gets all countries for the country selector
            SelectList countries = new SelectList(CountryInfoProvider.GetCountries(), "CountryID", "CountryDisplayName");

            // Gets the current customer
            Customer customer = cart.Customer;

            // Gets all customer billing addresses for the address selector
            IEnumerable <CustomerAddress> customerAddresses = Enumerable.Empty <CustomerAddress>();

            if (customer != null)
            {
                customerAddresses = addressRepository.GetByCustomerId(customer.ID);
            }

            // Prepares address selector options
            SelectList addresses = new SelectList(customerAddresses, "ID", "Name");

            // Gets all enabled shipping options for the shipping option selector
            SelectList shippingOptions = new SelectList(shippingOptionRepository.GetAllEnabled(), "ShippingOptionID", "ShippingOptionDisplayName");

            // Loads the customer details
            DeliveryDetailsViewModel model = new DeliveryDetailsViewModel
            {
                Customer       = new CustomerModel(cart.Customer),
                BillingAddress = new BillingAddressModel(cart.BillingAddress, countries, addresses),
                ShippingOption = new ShippingOptionModel(cart.ShippingOption, shippingOptions)
            };

            // Displays the customer details step
            return(View(model));
        }
        //Vue affichant la liste des livraisons affilié à un livreur avec modele DeliveryDetailsViewModel
        public ActionResult ListeDeliverys(int idDeliveryman)
        {
            List <DeliveryDetailsViewModel> listeDelivery = new List <DeliveryDetailsViewModel>();

            idDeliveryman = HttpContext.Session.GetInt32("IdDeliveryman").GetValueOrDefault();
            List <DTO.Delivery> listDeliverys = DeliveryManager.GetAllDelivery(idDeliveryman);

            foreach (DTO.Delivery d in listDeliverys)
            {
                DeliveryDetailsViewModel deliveryDetails = new DeliveryDetailsViewModel();
                deliveryDetails.Deliverys      = d;
                deliveryDetails.Orders         = OrderManager.GetOrder(d.FK_idOrder);
                deliveryDetails.Restaurants    = RestaurantManager.GetRestaurant(d.FK_idRestaurant);
                deliveryDetails.Delivery_Times = Delivery_TimeManager.GetDelivery_Time(d.FK_idDelivery_Time);

                listeDelivery.Add(deliveryDetails);
            }

            return(View(listeDelivery));
        }
        /// <summary>
        /// Prepares a view model of the preview checkout process step including the shopping cart,
        /// the customer details, and the payment method.
        /// </summary>
        /// <returns>View model with information about the future order.</returns>
        private PreviewAndPayViewModel PreparePreviewViewModel()
        {
            // Gets the current user's shopping cart
            ShoppingCartInfo cart = shoppingService.GetCurrentShoppingCart();

            // Prepares the customer details
            DeliveryDetailsViewModel deliveryDetailsModel = new DeliveryDetailsViewModel
            {
                Customer       = new CustomerViewModel(shoppingService.GetCurrentCustomer()),
                BillingAddress = new BillingAddressViewModel(shoppingService.GetBillingAddress(), null, null),
                ShippingOption = new ShippingOptionViewModel()
                {
                    ShippingOptionID          = cart.ShippingOption.ShippingOptionID,
                    ShippingOptionDisplayName = ShippingOptionInfoProvider.GetShippingOptionInfo(cart.ShippingOption.ShippingOptionID).ShippingOptionDisplayName
                }
            };

            // Prepares the payment method
            PaymentMethodViewModel paymentViewModel = new PaymentMethodViewModel
            {
                PaymentMethods = new SelectList(GetApplicablePaymentMethods(cart), "PaymentOptionID", "PaymentOptionDisplayName")
            };

            // Gets the selected payment method
            PaymentOptionInfo paymentMethod = cart.PaymentOption;

            if (paymentMethod != null)
            {
                paymentViewModel.PaymentMethodID = paymentMethod.PaymentOptionID;
            }

            // Prepares a model from the preview step
            PreviewAndPayViewModel model = new PreviewAndPayViewModel
            {
                DeliveryDetails = deliveryDetailsModel,
                Cart            = new ShoppingCartViewModel(cart),
                PaymentMethod   = paymentViewModel
            };

            return(model);
        }
        //EndDocSection:PreparePayment

        //DocSection:PreparePreview
        /// <summary>
        /// Prepares a view model of the preview checkout process step including the shopping cart,
        /// the customer details, and the payment method.
        /// </summary>
        /// <returns>View model with information about the future order.</returns>
        private PreviewAndPayViewModel PreparePreviewViewModel()
        {
            // Gets the current user's shopping cart
            ShoppingCart cart = shoppingService.GetCurrentShoppingCart();

            // Prepares the customer details
            DeliveryDetailsViewModel deliveryDetailsModel = new DeliveryDetailsViewModel
            {
                Customer       = new CustomerModel(cart.Customer),
                BillingAddress = new BillingAddressModel(cart.BillingAddress, null, null)
            };

            // Prepares the payment method
            PaymentMethodViewModel paymentViewModel = new PaymentMethodViewModel
            {
                PaymentMethods = new SelectList(GetApplicablePaymentMethods(cart), "PaymentOptionID", "PaymentOptionDisplayName")
            };

            // Gets the selected payment method if any
            PaymentOptionInfo paymentMethod = cart.PaymentMethod;

            if (paymentMethod != null)
            {
                paymentViewModel.PaymentMethodID = paymentMethod.PaymentOptionID;
            }

            // Prepares a model from the preview step
            PreviewAndPayViewModel model = new PreviewAndPayViewModel
            {
                DeliveryDetails = deliveryDetailsModel,
                Cart            = cart,
                PaymentMethod   = paymentViewModel
            };

            return(model);
        }