public ActionResult UpdateCart(Guid id, int qty)
        {
            // Remove the item from the cart
            var cart = ShoppingCart.GetCart(this.HttpContext);

            // Get the name of the product to display confirmation
            string productName = _dbContext.Carts
                                 .Single(item => item.RecordId == id).Product.name;


            // Remove from cart
            int itemCount = cart.RemoveFromCart(id, qty);

            // Display the confirmation message
            var results = new ShoppingCartUpdateViewModel
            {
                Message = Server.HtmlEncode(productName) +
                          " updated",
                CartTotal = cart.GetTotal(),
                CartCount = cart.GetCount(),
                ItemCount = itemCount,
                DeleteId  = id
            };

            return(Json(results));
        }
Example #2
0
        public ActionResult UpdateCart(int id, int qty)
        {
            var    cart      = ShoppingCart.GetCart(this.HttpContext);
            string bookName  = dbc.Carts.Single(item => item.BookId == id).Book.Title;
            int    itemCount = cart.UpdateCart(id, qty);

            var results = new ShoppingCartUpdateViewModel
            {
                Message   = "The quantity of " + Server.HtmlEncode(bookName) + " has been updated.",
                CartTotal = cart.GetTotal(),
                CartCount = cart.GetCount(),
                ItemCount = itemCount,
                ItemId    = id
            };

            return(Json(results));
        }