public ActionResult RemoveFromCart(int id) { //Remove the item from the cart var cart = ShoppingCart.GetCart(this.HttpContext); //Get the name of the item to display confirmation //Get the name of the album to display confirmation string itemName = db.tb_producto .Single(item => item.id_producto == id).nombre_prod; //Remove from cart int itemCount = cart.RemoveFromCart(id); //Display the confirmation message var results = new ShoppingCartRemoveViewModel { Message = "One (1) " + Server.HtmlEncode(itemName) + " ha sido eliminado de su carrito.", CartTotal = cart.GetTotal(), CartCount = cart.GetCount(), ItemCount = itemCount, DeleteId = id }; return Json(results); }
public ActionResult AddToCart(int id) { // Retrieve the item from the database var addedItem = db.tb_producto .Single(item => item.id_producto == id); // Add it to the shopping cart var cart = ShoppingCart.GetCart(this.HttpContext); int count = cart.AddToCart(addedItem); // Display the confirmation message var results = new ShoppingCartRemoveViewModel { Message = Server.HtmlEncode(addedItem.nombre_prod) + " has been added to your shopping cart.", CartTotal = cart.GetTotal(), CartCount = cart.GetCount(), ItemCount = count, DeleteId = id }; return Json(results); }