public async Task<ActionResult> AddToCart(int id) { // Retrieve the item from the database var foundItem = await _svc.GetItem(id); var cart = ShoppingCart.GetCart(this.HttpContext, _svc); int count = cart.AddToCart(foundItem); var results = new ShoppingCartRemoveViewModel() { Message = Server.HtmlEncode(foundItem.Name) + " has been added to your shopping cart.", CartTotal = cart.GetTotal(), CartCount = cart.GetCount(), ItemCount = count, DeleteId = id }; return Json(results); }
public async Task<ActionResult> RemoveFromCart(int id) { // Remove the item from the cart var cart = ShoppingCart.GetCart(this.HttpContext, _svc); // Get the name of the item to display confirmation // Get the name of the album to display confirmation //string itemName = storeDB.Items // .Single(item => item.ID == id).Name; //var anItem = await _svc.GetItem(id); var anItem = _svc.GetCartItem(cart.ShoppingCartId, id); string itemName = anItem.ItemName; // Remove from cart int itemCount = await cart.RemoveFromCart(id); // Display the confirmation message var results = new ShoppingCartRemoveViewModel { Message = "One (1) " + Server.HtmlEncode(itemName) + " has been removed from your shopping cart.", CartTotal = cart.GetTotal(), CartCount = cart.GetCount(), ItemCount = itemCount, DeleteId = id }; return Json(results); }