public IActionResult OnPost()
        {
            // If all the information is valid as per validation checks
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Movie.Genres = string.Join(',', GenresSelection.Where(selection => selection.IsSelected)
                                       .Select(selection => Enum.Parse(typeof(Genre), selection.GenreValue)));

            if (Movie.Id > 0)
            {
                movieData.Update(Movie);
            }
            else
            {
                movieData.Add(Movie);
            }

            movieData.Commit();

            // TempData works like a dictionary with the key/value pairs
            TempData["Message"] = "Movie saved!";
            return(RedirectToPage("./Detail", new { movieId = Movie.Id }));
        }
示例#2
0
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Movie movie = await PopulateMovieAsync();

            if (movie is null)
            {
                return(Page());
            }

            if (movie.Id > 0)
            {
                _movieData.Update(movie);
            }
            else
            {
                _movieData.Add(movie);
            }

            _movieData.Commit();

            // TempData works like a dictionary with the key/value pairs
            TempData["Message"] = "Movie saved!";
            return(RedirectToPage("./Detail", new { movieId = movie.Id })); // TODO: check if needed
        }
示例#3
0
        public IActionResult OnPost(int movieId)
        {
            Movie = _movieData.Delete(movieId);
            _movieData.Commit();

            if (Movie == null)
            {
                return(RedirectToPage("./NotFound"));
            }

            return(RedirectToPage("./List"));
        }
示例#4
0
        public async Task <IActionResult> AddUserMovie(AddViewModel userMovieViewModel)
        {
            //Add to UserMoviesList
            if (ModelState.IsValid)
            {
                var currentUserId = _userManager.GetUserId(HttpContext.User);
                var movie         = _sqlMovieData.GetComplete(userMovieViewModel.MovieId);

                var movieToAdd = new UserMovie()
                {
                    Added       = DateTime.UtcNow,
                    MovieId     = userMovieViewModel.MovieId,
                    UserComment = userMovieViewModel.Comment,
                    UserRating  = userMovieViewModel.Rating
                };

                var resultMovie = await _userMovieData.Add(currentUserId, movieToAdd);

                movie = _sqlMovieData.AddUser(movie, currentUserId);

                //Add rating to AllMoviesList
                if (resultMovie.UserRating != 0)
                {
                    _sqlMovieData.SetUserAverage(movie);
                }

                _sqlMovieData.Commit();
                return(RedirectToAction(controllerName: "movie", actionName: "about", routeValues: new { id = movie.Id }));
            }
            return(View());
        }
        public IActionResult OnPost(int movieId)
        {
            var movie = movieData.Delete(movieId);

            movieData.Commit();

            if (movie == null)
            {
                return(RedirectToPage("./NotFound"));
            }
            TempData["Message"] = $"{movie.Name} deleted";
            return(RedirectToPage("./Index"));
        }
        public IActionResult OnPost(int movieId)
        {
            var movie = _movieData.Delete(movieId);

            if (movie is null)
            {
                return(RedirectToPage("./NotFound"));
            }

            _movieData.Commit();

            TempData["Message"] = $"{movie.Title} deleted";
            return(RedirectToPage("./List"));
        }
示例#7
0
 public IActionResult OnPost(int?id)
 {
     if (ModelState.IsValid)
     {
         if (Movie.Id > 0)
         {
             Movie = movieData.Update(Movie);
         }
         else
         {
             Movie = movieData.Add(Movie);
         }
         movieData.Commit();
         return(RedirectToPage("./Detail", new { id = Movie.Id }));
     }
     return(Page());
 }
 public IActionResult OnPost()
 {
     if (!ModelState.IsValid)
     {
         Ratings = htmlHelper.GetEnumSelectList <Rating>();
         return(Page());
     }
     if (Movie.MovieId > 0)
     {
         movieData.Update(Movie);
     }
     else
     {
         movieData.Add(Movie);
     }
     movieData.Commit();
     TempData["Message"] = "Movie saved: " + Movie.Title;
     return(RedirectToPage("./Detail", new { movieId = Movie.MovieId }));
 }
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                Genre = htmlHelper.GetEnumSelectList <Genre>();
                return(Page());
            }

            if (Movie.Id > 0)
            {
                movieData.Update(Movie);
            }
            else
            {
                movieData.Add(Movie);
            }
            TempData["Message"] = "Movie Saved!";
            movieData.Commit();
            return(RedirectToPage("./Detail", new { movieId = Movie.Id }));
        }
示例#10
0
 public ActionResult <Movie> Post([FromBody] Movie newMovie)
 {
     movieData.Add(newMovie);
     movieData.Commit();
     return(CreatedAtAction("Get", new { id = newMovie.Id }, newMovie));
 }