public async Task <ServiceResponse <ProductDto_ToReturn> > UpdateProduct(ProductDto_ToUpdate product, int id) { var oldProduct = await _dbContext.Products.Where(x => x.Id == id).FirstOrDefaultAsync(); if (oldProduct != null) { oldProduct.Name = product.Name; oldProduct.Price = product.Price; oldProduct.IsActive = product.IsActive; oldProduct.ProductGroupId = product.ProductGroupId; await _dbContext.SaveChangesAsync(); return(ResponseResult.Success(_mapper.Map <ProductDto_ToReturn> ( await _dbContext.Products.Include(x => x.ProductGroups).Where(x => x.Id == id).FirstOrDefaultAsync() ))); } else { return(ResponseResult.Failure <ProductDto_ToReturn>("Not found product id")); } }
public async Task <IActionResult> UpdateProduct(ProductDto_ToUpdate product, int id) { return(Ok(await _productService.UpdateProduct(product, id))); }