コード例 #1
0
        public void Remove(Int64 id)
        {
            BeginTransaction();

            var shoppingCartItem = _shoppingCartItemService.GetById(id);

            shoppingCartItem.Active = false;

            _shoppingCartItemService.Update(shoppingCartItem);

            Commit();
        }
コード例 #2
0
        public JsonResult DeleteProduct(int id)
        {
            var shppingCart = _shoppingCartItemService.GetById(id);

            _shoppingCartItemService.Delete(shppingCart);

            var jsonResult = Json(new { success = true }, JsonRequestBehavior.AllowGet);

            return(jsonResult);
        }
コード例 #3
0
        //sepete ürün ekleme
        public IActionResult Post([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));
            }
            else if (selectedProduct.StockQuantity <= 0 || selectedProduct.StockQuantity <= selectedProduct.MinStockQuantity)
            {
                response.HasError = true;
                response.Errors.Add("Selected Product Has No Stock!");

                return(BadRequest(response));
            }
            else if (selectedProduct.StockQuantity - model.Quantity <= selectedProduct.MinStockQuantity)
            {
                response.HasError = true;
                response.Errors.Add("Stock Of Selected Product Is Not Enough!");

                return(BadRequest(response));
            }

            var shoppingCartItem = _shoppingCartItemService.GetEx(s => s.CustomerUserName == model.CustomerUsername && s.ProductId == model.ProductId).FirstOrDefault();

            if (shoppingCartItem == null)
            {
                ShoppingCartItem newShoppingCartItem = new ShoppingCartItem
                {
                    CustomerUserName = model.CustomerUsername,
                    ProductId        = model.ProductId,
                    Quantity         = model.Quantity
                };

                _shoppingCartItemService.AddToCart(model.CustomerUsername, newShoppingCartItem);

                response.Entity = _shoppingCartItemService.GetById(newShoppingCartItem.Id);
            }
            else
            {
                shoppingCartItem.Quantity += model.Quantity;
                _shoppingCartItemService.AddToCart(model.CustomerUsername, shoppingCartItem);

                response.Entity = _shoppingCartItemService.GetById(shoppingCartItem.Id);
            }

            response.IsSuccess = true;

            return(Ok(response));
        }