public ActionResult RemoveFromCart(int id)
        {
            var cart = ShoppingCartLogic.GetCart(this.HttpContext);

            var     shoppingCart    = new ShoppingCartLogic();
            int     productId       = shoppingCart.GetCartItemProductId(id);
            var     productService  = new ProductLogic();
            Product productToRemove = productService.FindProduct(productId);

            int itemCount = cart.RemoveFromCart(id);

            var removeViewModel = new ShoppingCartRemoveVM
            {
                Message = Server.HtmlEncode(productToRemove.Name) +
                          " has been removed from your shopping cart.",
                CartCount    = cart.GetCount(),
                CartSubTotal = cart.GetSubtotal(),
                CartSalesTax = cart.GetSalesTax(),
                CartTotal    = cart.GetTotal(),
                ItemCount    = itemCount,
                DeleteId     = id,
            };

            return(Json(removeViewModel));
        }
        public ActionResult RemoveFromCart(int id)
        {
            // Remove the item from the cart
            var cart = ShoppingCart.GetCart(this.HttpContext);

            // Get the name of the album to display confirmation
            string albumName = storeDB.Carts
                               .Single(item => item.RecordId == id).Product.Title;

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

            // Display the confirmation message
            var results = new ShoppingCartRemoveVM
            {
                Message = Server.HtmlEncode(albumName) +
                          " has been removed from your shopping cart.",
                CartTotal = cart.GetTotal(),
                CartCount = cart.GetCount(),
                ItemCount = itemCount,
                DeleteId  = id
            };

            HttpContext.Session["NumberOfAllItems"] = cart.GetCount();

            return(Json(results));
        }
Esempio n. 3
0
        //
        // AJAX: /ShoppingCart/RemoveFromCart/5

        //[HttpPost]
        public ActionResult RemoveFromCart(int id)
        {
            // Remove the item from the cart
            var cart = ShoppingCart.GetCart(this.HttpContext);

            // Get the name of the product to display confirmation
            string productName = storeDB.Products
                                 .Single(item => item.ProductId == id).ProductName;

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

            // Δεν χρειάζεται!
            // Display the confirmation message
            var results = new ShoppingCartRemoveVM
            {
                Message = "One (1)" + Server.HtmlEncode(productName) +
                          " has been removed from your shopping cart.",
                CartTotal = cart.GetTotal(),
                CartCount = cart.GetCount(),
                ItemCount = itemCount,
                DeleteId  = id
            };

            return(RedirectToAction("Index"));

            //return Json(results, JsonRequestBehavior.AllowGet);
        }
        public async Task <ActionResult> AddNumberOfProductToCart(int id)
        {
            // Remove the item from the cart
            var cart = ShoppingCart.GetCart(this.HttpContext);

            // Get the name of the album to display confirmation
            var product = storeDB.Carts
                          .Single(item => item.RecordId == id).Product;

            //var product = storeDB.Products.Find(id);

            // Remove from cart
            var cartItem = await cart.AddToCart(product);

            // Display the confirmation message
            var results = new ShoppingCartRemoveVM
            {
                Message = Server.HtmlEncode(product.Name) +
                          " has been removed from your shopping cart.",
                CartTotal = cart.GetTotal(),
                CartCount = cart.GetCount(),
                ItemCount = cartItem.Number,
                DeleteId  = id
            };

            HttpContext.Session["NumberOfAllItems"] = cart.GetCount();

            return(Json(results));
        }