Esempio n. 1
0
        //sepetten ürün çıkarma
        public IActionResult Put(int id, [FromBody] ShoppingCartItemModel model)
        {
            ServiceResponse <ShoppingCartItem> response = new ServiceResponse <ShoppingCartItem>();

            var selectedProduct = _productService.GetById(model.ProductId);

            if (selectedProduct == null)
            {
                response.HasError = true;
                response.Errors.Add("Selected Product Does Not Exist!");

                return(BadRequest(response));
            }
            else if (selectedProduct.Deleted || !selectedProduct.Published)
            {
                response.HasError = true;
                response.Errors.Add("Selected Product Does Not Publish!");

                return(BadRequest(response));
            }

            ShoppingCartItem shoppingCartItem = _shoppingCartItemService.GetById(id);

            if (shoppingCartItem == null)
            {
                response.HasError = true;
                response.Errors.Add("Shopping Cart Item Does Not Exist!");

                return(BadRequest(response));
            }

            _shoppingCartItemService.RemoveFromCart(shoppingCartItem);

            response.Entity    = _shoppingCartItemService.GetById(id);
            response.IsSuccess = true;

            return(Ok(response));
        }