public ActionResult Edit(int id) { var service = CreateMovieReviewService(); var detail = service.GetMovieReviewById(id); var model = new MovieReviewEdit { MovieReviewId = detail.MovieReviewId, MovieTitle = detail.MovieTitle, MovieReleaseYear = detail.MovieReleaseYear, Director = detail.Director, MovieGenre = detail.MovieGenre, MovieMania = detail.MovieMania, MovieRating = detail.MovieRating }; return(View(model)); }
public bool UpdateMovieReview(MovieReviewEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .MovieReviews .Single(e => e.MovieReviewId == model.MovieReviewId && e.OwnerId == _userId); entity.MovieTitle = model.MovieTitle; entity.MovieReleaseYear = model.MovieReleaseYear; entity.Director = model.Director; entity.MovieGenre = model.MovieGenre; entity.MovieStance = model.MovieStance; entity.MovieRating = model.MovieRating; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, MovieReviewEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.MovieReviewId != id) { ModelState.AddModelError("", "ID Mismatch"); return(View(model)); } var service = CreateMovieReviewService(); if (service.UpdateMovieReview(model)) { TempData["SaveResult"] = "Your review has been updated"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your review could not be updated at this moment"); return(View(model)); }