Exemplo n.º 1
0
        //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));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets address with <paramref name="addressID"/> ID, but only if the address belongs to the customer used by shopping cart.
        /// </summary>
        /// <param name="addressID">The identifier of the address.</param>
        /// <returns>Address of the customer used by shopping cart. <c>Null</c> if customer does not have address with given Id.</returns>
        public AddressInfo GetCustomerAddress(int addressID)
        {
            var customer = mShoppingService.GetCurrentShoppingCart().Customer;

            return(mAddressRepository.GetByCustomerId(customer.CustomerID).FirstOrDefault(a => a.AddressID == addressID));
        }