Exemplo n.º 1
0
        public async Task <IActionResult> CreateProduct([FromBody] ProductPutPostDto productDTO)
        {
            if (ModelState.IsValid)
            {
                var product = new Product();
                product.Name        = productDTO.Name;
                product.Description = productDTO.Description;
                product.Price       = productDTO.Price;
                //product.PhotoUrl = "";
                product.SupplierId = productDTO.SupplierId;
                var addResult = await _products.CreateAsync(product);

                if (addResult == null)
                {
                    return(BadRequest("try again"));
                }
                //var addResult=_seeder.addProduct(product);
                // if (!addResult)
                // {
                //     return BadRequest("try again");
                //         }
                // return Ok(product);
                return(Created("created", productDTO));
            }
            return(BadRequest());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateProduct(int id, [FromBody] ProductPutPostDto updatedProductDTO)
        {
            var updatedProduct = new Product();

            updatedProduct.Id          = id;
            updatedProduct.Name        = updatedProductDTO.Name;
            updatedProduct.Description = updatedProduct.Description;
            updatedProduct.Price       = updatedProductDTO.Price;
            updatedProduct.PhotoUrl    = updatedProductDTO.PhotoUrl;
            updatedProduct.SupplierId  = updatedProductDTO.SupplierId;
            var updateReslt = await _products.UpdateAsync(updatedProduct);

            //var updateReslt = _seeder.updateProduct(updatedProduct);
            if (updateReslt)
            {
                return(Ok(updatedProduct));
            }
            return(BadRequest("product wasnt found try again"));
        }