public ActionResult Create(MovieReviewCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateMovieReviewService();

            if (service.CreateMovieReview(model))
            {
                TempData["SaveResult"] = "Your review has been successfully created";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Review could not be created at this time.");
            return(View(model));
        }
Пример #2
0
        public bool CreateMovieReview(MovieReviewCreate model)
        {
            var entity =
                new MovieReview()
            {
                OwnerId          = _userId,
                MovieTitle       = model.MovieTitle,
                MovieReleaseYear = model.MovieReleaseYear,
                Director         = model.Director,
                MovieGenre       = model.MovieGenre,
                MovieStance      = model.MovieStance,
                MovieRating      = model.MovieRating
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.MovieReviews.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }