Esempio n. 1
0
        public async Task <IActionResult> Index()
        {
            var sessionCart = HttpContext.Session.GetData <ShoppingCart>();

            if (!(sessionCart is null))
            {
                var cartItems = await _shoppingCartService.GetShoppingCartAsync();

                if (sessionCart.Items.Count() == cartItems.Count())
                {
                    return(View(sessionCart));
                }
            }

            var cart = await InitializeShoppingCartAsync();

            cart = await _campaignService.CalculateAsync(cart);

            cart = await _couponService.CalculateAsync(cart);

            cart.DeliveryCost = await _deliveryService.CalculateDeliveryCostAsync(cart.Items,
                                                                                  COST_PER_DELIVERY, COST_PER_PRODUCT, FIXED_COST);

            //Save shopping cart.
            HttpContext.Session.SetData(cart);

            return(View(cart));
        }