public async Task <IActionResult> AddToShoppingCart(int productId, int p = 0)
        {
            await _shoppingCart.AddToCart(productId);

            if (p == 1)
            {
                Key = "success";
                var callbackUrl = Url.Action(nameof(Index));
                Message = $"Product with id  {productId} added to <a href='{callbackUrl}'>Shopping cart</a>";
                return(RedirectToAction("Index", "Home"));
            }
            return(RedirectToAction(nameof(Index)));
        }
예제 #2
0
        private void AddToCart()
        {
            int quantity = int.Parse(Quantity);

            // If true, update quantity on the item already in the cart
            if (ShoppingCartHelper.IsAlreadyInCart(Product, SelectedSize.Size))
            {
                ShoppingCartHelper.UpdateItemQuantity(Product.ProductId, SelectedSize.Size, quantity);
                return;
            }

            var productVM = new ProductViewModel
            {
                ProductId   = Product.ProductId,
                Name        = Product.Name,
                Description = Product.Description,
                ImageUrl    = Product.ImageUrl,
                Quantity    = quantity,
                Size        = SelectedSize.Size,
                Cost        = SelectedSize.Cost * quantity
            };

            ShoppingCartHelper.AddToCart(productVM);
        }