public async Task <IActionResult> CreateProdut(ProductForCreationOrUpdate productForCreation) { var product = this.mapper.Map <Product>(productForCreation); product.Created = DateTime.Now; product.LastUpdated = DateTime.Now; this.unitOfWork.Add(product); if (await this.unitOfWork.CompleteAsync()) { return(Ok(product.Id)); } return(BadRequest("Could not create the product")); }
public async Task <IActionResult> Updateproduct(int id, ProductForCreationOrUpdate productForUpdate) { var product = await this.repo.GetProduct(id); product.LastUpdated = DateTime.Now; this.mapper.Map(productForUpdate, product); if (await this.unitOfWork.CompleteAsync()) { var updatedProduct = await this.repo.GetProduct(product.Id); var productToReturn = this.mapper.Map <ProductForDetail>(updatedProduct); return(CreatedAtRoute("GetProduct", new { id = product.Id }, productToReturn)); } return(BadRequest("Could not update the product")); }