Пример #1
0
        public ActionResult DecrementProductQuantity(CartVM viewModel)
        {
            List <ShoppingCartProduct> scps = new List <ShoppingCartProduct>();

            int qty = viewModel.Quantity; // this is to pass by reference to have the variable at return time

            // If we are a guest on the site use cookies for the shopping cart
            if (!UserService.IsUserConnected(System.Web.HttpContext.Current.User))
            {
                HttpCookie cookie = CookieService.Decrement(Request.Cookies, viewModel.ProductId,
                                                            viewModel.Size, ref qty);
                HttpContext.Response.SetCookie(cookie);

                scps = CookieService.GetShoppingCartProducts(cookie);
            }
            else // We are connected with a user account
            {
                ShoppingCartManager shoppingCartManager = new ShoppingCartManager();

                qty = shoppingCartManager.DecrementQuantity(User.Identity.GetUserId(), viewModel.ProductId, viewModel.Size);
                //TODO : Check error message and show it in view if error occured


                ShoppingCart shoppingCart = new ShoppingCartManager().GetShoppingCartByUser(User.Identity.GetUserId());

                scps = new ShoppingCartProductManager().GetShoppingCartProductByShoppingCartId(shoppingCart.ShoppingCartId);
            }

            return(Json(new { price = ShoppingCartService.GetSubTotal(scps, CookieService.GetCurrency(Request.Cookies)), qty }, JsonRequestBehavior.AllowGet));
        }