Esempio n. 1
0
        public IActionResult MyCart()
        {
            var cart = shoppingCartManager.GetCart();

            return(View(new ShoppingCartViewModel()
            {
                CartItems = cart.Items, ShoppingCartTotal = cart.Total
            }));
        }
Esempio n. 2
0
        /// <summary>
        /// This method invokes shopping cart view component
        /// </summary>
        /// <param name="userName"></param>
        /// <returns>a component view of all items</returns>
        public async Task <IViewComponentResult> InvokeAsync(string userName)
        {
            //var user = await _userManager.FindByEmailAsync(userName);
            //string userID = user.Id;
            var cart = await _shoppingCartManager.GetCart(userName);

            IEnumerable <ShoppingCartItem> items = await _shoppingCartItemManager.GetItemsForSpecificCart(cart.ID);

            return(View(items));
        }
Esempio n. 3
0
        private Order TransformCartToOrder(Order order)
        {
            var cart = _shoppingCartManager.GetCart();

            foreach (var item in cart.Items)
            {
                var orderItem = CreateOrderItem();
                orderItem.Order      = order;
                orderItem.OrderId    = order.OrderId;
                orderItem.Quantity   = item.Quantity;
                orderItem.DrinkPrice = item.Drink.Price * item.Quantity;
                orderItem.DrinkId    = item.Drink.DrinkId;
                order.OrderTotal    += orderItem.DrinkPrice;
                _appDbContext.Add(orderItem);
            }


            return(order);
        }
        public async Task <IActionResult> AddToCart(int id)
        {
            Product product = await _inventory.GetbyID(id);

            if (product != null)
            {
                var user = await _userManager.GetUserAsync(User);

                var userName = user.UserName;

                ShoppingCart cart = await _cart.GetCart(userName);

                ShoppingCartItem cartItem = new ShoppingCartItem(cart.ID, product, 1);

                await _cartItem.SaveCartItem(cartItem);

                cart.ShoppingCartItems.Add(cartItem);

                await _cart.SaveCart(cart);
            }

            return(RedirectToAction("Index"));
        }