Skip to content

Instantly share code, notes, and snippets.

@hudo
Created February 9, 2018 12:09
Show Gist options
  • Save hudo/4637a0daf14c1818c9c2e9c873652cf0 to your computer and use it in GitHub Desktop.
Save hudo/4637a0daf14c1818c9c2e9c873652cf0 to your computer and use it in GitHub Desktop.
[HttpPost, ValidateAnyForgeryToken]
public async Task<IActionResult> Save(ProductModel model)
{
if(!ModelState.IsValid)
return View(model);
// invoke some business logic magic that makes money
try
{
await _dbContext.SaveChanges();
}
catch(Exception e)
{
_logger.LogError("message", e);
ModelState.AddModelError("exception", "Houston we have a problem:" + e.Message);
return View(model);
}
return RedirectToActio("Read", new { id = model.Id });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment