public void UpdateInstantGame(UpdateInstantGameCommand cmd) { var game = _context.InstantGames.Find(cmd.Id); if (game == null) { throw new Exception("Unable to find the instant game"); } if (game.IsDeleted) { throw new Exception("Unable to update a deleted instant game"); } cmd.UpdateInstantGame(game); _context.SaveChanges(); }
public IActionResult Edit(UpdateInstantGameCommand command) { try { if (ModelState.IsValid) { _service.UpdateInstantGame(command); return(RedirectToAction(nameof(View), new { id = command.Id })); } } catch (Exception) { // TODO: Log error // Add a model-level error by using an empty string key ModelState.AddModelError( string.Empty, "An error occured saving the instant game" ); } //If we got to here, something went wrong return(View(command)); }