public ActionResult Create(Game game) { if (ViewData.ModelState.IsValid && game.IsValid()) { gameRepository.SaveOrUpdate(game); Message = "Игра успешно создана."; return this.RedirectToAction(c => c.Index()); } return View(game); }
public ActionResult Edit(Game game) { Game gameToUpdate = gameRepository.Get(game.Id); TransferFormValuesTo(gameToUpdate, game); if (ViewData.ModelState.IsValid && game.IsValid()) { Message = "Игра успешно изменена."; return this.RedirectToAction(c => c.Index()); } gameRepository.DbContext.RollbackTransaction(); return View(game); }
public AjaxFormResult SaveGame(Game game) { var response = new AjaxFormResult(); try { Game gameToUpdate = gameRepository.Get(game.Id); TransferGameFormValuesTo(gameToUpdate, game); if (ViewData.ModelState.IsValid && game.IsValid()) { response.Success = true; } else { response.Success = false; response.Errors.Add(new FieldError("Game_ID", "The ID field is required")); } } catch (Exception e) { response.Success = false; response.ExtraParams["msg"] = e.ToString(); } return response; }