예제 #1
0
        public IResult UpdateBasketProductByModel(CartDtoForUpdate model)
        {
            var product = _productService.GetById(model.ProductId);

            if (product == null)
            {
                return(new ErrorResult(Messages.ProductNotFound));
            }
            var basketProduct = _cartDal.Get(x => x.Product.Id == model.ProductId);

            if (model.Quantity == 0)
            {
                _cartDal.Delete(basketProduct);
                return(new SuccessResult(Messages.CartProductDeleted));
            }
            else if (model.Quantity < 0)
            {
                return(new ErrorResult(Messages.CartProductQuantityCannotBeNegative));
            }
            else if (product.UnitsInStock - model.Quantity < 0)
            {
                return(new ErrorResult(string.Concat(Messages.CartProductNotAddedMore, " Stok Adedi :", product.UnitsInStock)));
            }

            basketProduct.Quantity = model.Quantity;
            _cartDal.Update(basketProduct);
            return(new SuccessResult(Messages.CartProductUpdated));
        }
예제 #2
0
 public ActionResult UpdateCart(CartDtoForUpdate model)
 {
     return(Json(_cartService.UpdateBasketProductByModel(model)));
 }