Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created February 9, 2022 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcomartin/83e1f605f7e05e55314716dea15ab0f1 to your computer and use it in GitHub Desktop.
Save dcomartin/83e1f605f7e05e55314716dea15ab0f1 to your computer and use it in GitHub Desktop.
[HttpPost("/productCrud/{sku}")]
public async Task<IActionResult> UpdateProduct([FromRoute] string sku, [FromForm]CatalogProduct product)
{
var record = await _catalogDbContext.Products.SingleOrDefaultAsync(x => x.Sku == sku);
if (product == null)
{
return NotFound();
}
record.Description = product.Description;
record.Name = product.Name;
record.Price = product.Price;
record.Cost = product.Cost;
record.QuantityOnHand = product.QuantityOnHand;
record.ForSale = product.Price > 0 && product.QuantityOnHand > 0 && product.ForSale;
record.FreeShipping = product.FreeShipping;
await _catalogDbContext.SaveChangesAsync();
return RedirectToAction("GetProduct", new { sku = sku });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment