public async Task <IActionResult> ViewBasket()
        {
            string username = HttpContext.User.Identity.Name;

            //Get user's basket by username
            Basket basket = await _basketManager.FindBasketByUserEager(username);

            // If basket for user doesn't exist yet, create empty one, but don't add it to DB
            if (basket == null)
            {
                basket = new Basket()
                {
                    ID          = 0,
                    UserName    = username,
                    Subtotal    = 0,
                    BasketItems = new List <BasketItem>()
                };
            }
            else
            {
                basket.CalcSubtotal();
                await _basketManager.UpdateBasket(basket);
            }
            return(View(basket));
        }
Beispiel #2
0
        public async Task <IViewComponentResult> InvokeAsync(string username)
        {
            Basket basket = await _basketManager.FindBasketByUserEager(username);

            if (basket == null)
            {
                return(View(new List <BasketItem>()));
            }

            return(View(basket.BasketItems));
        }
Beispiel #3
0
        public async Task <IActionResult> ShippingDetails(string username)
        {
            //Get user's basket by username
            Basket basket = await _basketManager.FindBasketByUserEager(username);

            // If basket for user doesn't exist yet, create empty one, but don't add it to DB
            if (basket == null)
            {
                RedirectToAction("ViewBasket", "Basket");
            }
            else
            {
                basket.CalcSubtotal();
                await _basketManager.UpdateBasket(basket);
            }
            OrderConfirmation orderConfirmation = new OrderConfirmation {
                ShippingDetails = new ShippingDetails(), Basket = basket, TransactionFailure = false
            };

            return(View(orderConfirmation));
        }