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 })); }
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")); }