public async Task <IActionResult> Add([FromBody] ProductWriteDTO _product) { Product product = _mapper.Map <Product>(_product); await _context.Product.AddAsync(product); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { return(Conflict()); } return(Ok(_mapper.Map <ProductReadDTO>(product))); }
public IActionResult AddNew(ProductWriteDTO product) { if (product != null) { if (product.category_id != null) { product.category = _catrepo.GetOneById(product.category_id); Product productNew = _mapper.Map <Product>(product); _repo.Add(productNew); if (_repo.SaveChanges() > 0) { return(Ok("created")); } } } return(BadRequest()); }