public async Task <IActionResult> AddProduct([FromBody] ProductAddDto newP) { if (!ModelState.IsValid) { return(BadRequest("Səhv özəlliklər daxil edilib." + ModelState)); } var result = await _repo.AddProduct(newP); if (result.IsSucces) { return(Ok(result.Content)); } return(StatusCode(520, result.Message)); }
public ActionResult <Product> AddProduct(ProductAddDto productAddDto) { var product = _mapper.Map <Product>(productAddDto); try { _repository.AddProduct(product); if (_repository.SaveChanges()) { return(CreatedAtAction(nameof(GetProductById), new { Id = product.Id }, product)); } } catch { return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } return(BadRequest()); }