public ActionResult Edit(int id) { var service = CreateGameReviewService(); var detail = service.GetGameReviewById(id); var model = new GameReviewEdit { GameReviewId = detail.GameReviewId, GameTitle = detail.GameTitle, GameDeveloper = detail.GameDeveloper, Platform = detail.Platform, GameGenre = detail.GameGenre, GameReleaseYear = detail.GameReleaseYear, GameMania = detail.GameMania, GameRating = detail.GameRating }; return(View(model)); }
public bool UpdateGameReview(GameReviewEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .GameReviews .Single(e => e.GameReviewId == model.GameReviewId && e.OwnerId == _userId); entity.GameTitle = model.GameTitle; entity.GameDeveloper = model.GameDeveloper; entity.Platform = model.Platform; entity.GameGenre = model.GameGenre; entity.GameReleaseYear = model.GameReleaseYear; entity.GameStance = model.GameStance; entity.GameRating = model.GameRating; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, GameReviewEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.GameReviewId != id) { ModelState.AddModelError("", "ID Mismatch"); return(View(model)); } var service = CreateGameReviewService(); if (service.UpdateGameReview(model)) { TempData["SaveResult"] = "Your review has been successfully updated"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your review could not be updated at this time"); return(View(model)); }