public async Task <IActionResult> CreateProduct([FromBody] SaveProductResource productResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var product = mapper.Map <SaveProductResource, Product>(productResource); product.CreatedOn = DateTime.Now; product.LastUpdate = DateTime.Now; repository.Add(product); await unitOfWork.CompleteAsync(); product = await repository.GetProduct(product.Id); var result = mapper.Map <Product, ProductsResource>(product); return(Ok(result)); }
public async Task <IActionResult> UpdateProduct(int id, [FromBody] SaveProductResource productResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var product = await repository.GetProduct(id); if (product == null) { return(NotFound()); } mapper.Map <SaveProductResource, Product>(productResource, product); product.LastUpdate = DateTime.Now; await unitOfWork.CompleteAsync(); product = await repository.GetProduct(product.Id); var result = mapper.Map <Product, ProductsResource>(product); return(Ok(result)); }