Пример #1
0
        public RedirectToActionResult AddToCart(int id, string returnUrl)
        {
            Product product = repository.Products
                              .FirstOrDefault(p => p.ProductID == id);

            if (product != null)
            {
                CartViewModel cart = GetCart();
                cart.AddItem(product, 1);
                SaveCart(cart);
            }
            return(RedirectToAction("Index", new { returnUrl }));
        }
Пример #2
0
        public async Task <IActionResult> CreateWithoutRedirect(string type, int id)
        {
            CartViewModel cartVm = await _service.GetCartFromSessionAsync(HttpContext, SESSION_KEY);

            if (!cartVm.Items.Any(i => i.Category == type && i.ItemID == id))
            {
                CartItemViewModel cartItemVm = await _service.CreateCartItemAsync(type, id);

                cartVm.AddItem(cartItemVm);
            }

            cartVm = await MergeCartsIfLogedIn(cartVm);

            return(RedirectToAction("Index", "Wishlist"));
        }