コード例 #1
0
        public IActionResult RemoveFromCart(int productId)
        {
            var cartActions = new ShoppingCartActions(_uow, HttpContext);
            var cart        = cartActions.ShoppingCart;

            cartActions.RemoveItem(productId);
            return(CreateView(cartActions, "_ShoppingCartItemsPartial", true));
        }
コード例 #2
0
        public ActionResult RemoveItemFromCart()
        {
            string rawId = Request.QueryString["ProductId"];
            int    productsId;

            if (!String.IsNullOrEmpty(rawId) && int.TryParse(rawId, out productsId))
            {
                using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
                {
                    String cartId = usersShoppingCart.GetCartId();
                    usersShoppingCart.RemoveItem(cartId, Convert.ToInt16(rawId));
                }
            }
            else
            {
                Debug.Fail("ERROR : We should never get to /ShoppingCart/AddItemQuantity without a ProductId.");
                throw new Exception("ERROR : It is illegal to load /ShoppingCart/AddItemQuantity without setting a ProductId.");
            }
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public ActionResult RemoveItemQuantity()
        {
            string rawId = Request.QueryString["ProductId"];
            int    productId;

            if (!String.IsNullOrEmpty(rawId) && int.TryParse(rawId, out productId))
            {
                using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
                {
                    String cartId          = usersShoppingCart.GetCartId();
                    var    allItems        = usersShoppingCart.GetCartItems();
                    int    currentQuantity = 0;
                    foreach (var item in allItems)
                    {
                        if (Convert.ToInt16(rawId) == item.ProductId)
                        {
                            currentQuantity = item.Quantity;
                        }
                    }
                    currentQuantity -= 1;
                    if (currentQuantity == 0)
                    {
                        usersShoppingCart.RemoveItem(cartId, Convert.ToInt16(rawId));
                    }
                    else
                    {
                        usersShoppingCart.UpdateItem(cartId, Convert.ToInt16(rawId), currentQuantity);
                    }
                }
            }
            else
            {
                Debug.Fail("ERROR : We should never get to /ShoppingCart/RemoveItem without a ProductId.");
                throw new Exception("ERROR : It is illegal to load /ShoppingCart/RemoveItem without setting a ProductId.");
            }
            return(RedirectToAction("Index"));
        }