Ejemplo n.º 1
0
        //form data is bound to argument automatically
        public async Task <IActionResult> Add(Movie movie)
        {
            if (!ModelState.IsValid)
            {
                //returning the page with the same data
                //for an unsuccessful post
                return(View(movie));
            }
            _context.Add(movie);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AddMovieToActor(int SelectedActorId, int SelectedMovieId)
        {
            var actor = await _context.Actors.SingleOrDefaultAsync(a => a.ID == SelectedActorId);

            var movie = await _context.Movies.SingleOrDefaultAsync(m => m.ID == SelectedMovieId);

            if (actor == null || movie == null)
            {
                return(NotFound());
            }
            //trying to add a movie already asssigned to an actor
            if (MovieActorPairExists(SelectedActorId, SelectedMovieId))
            {
                return(BadRequest());
            }

            _context.MovieActors.Add(new MovieActor {
                ActorId = SelectedActorId, MovieId = SelectedMovieId
            });
            await _context.SaveChangesAsync();

            //TODO: FIX THIS
            return(RedirectToAction(nameof(MoviesController.Index)));
        }