Ejemplo n.º 1
0
        // GET: Actors/Details/5
        public async Task <IActionResult> Details(int?id, string actorName)
        {
            var movieCastVM = new MovieCastViewModel();

            if (id == null && actorName == null)
            {
                return(NotFound());
            }
            else if (id == null)
            {
                id = (from m in _context.Actor
                      where m.Name == actorName
                      select m.ID).First();
            }

            var actor = await _context.Actor
                        .SingleOrDefaultAsync(m => m.ID == id);

            if (actor == null)
            {
                return(NotFound());
            }

            movieCastVM.actor = _context.Actor.Where(a => a.ID == id).First();
            movieCastVM.roles = (from r in _context.MovieRole
                                 join m in _context.Movie on r.Movie equals m
                                 join a in _context.Actor on r.Actor equals a
                                 where r.Actor.ID == id
                                 select new LoadMovieRole {
                Actor = a.Name, Character = r.Character, Movie = m.Title
            })
                                .OrderBy(r => r.Movie);

            return(View(movieCastVM));
        }
Ejemplo n.º 2
0
        // GET: Actors/Edit/5
        public async Task <IActionResult> Edit(int?id, string newMovie, string newRole)
        {
            var movieCastVM = new MovieCastViewModel();

            if (id == null)
            {
                return(NotFound());
            }

            var actor = await _context.Actor.SingleOrDefaultAsync(m => m.ID == id);

            if (actor == null)
            {
                return(NotFound());
            }

            movieCastVM.actor = _context.Actor.Where(a => a.ID == id).First();
            //Select all roles for current actor
            var movieRoles = from r in _context.MovieRole
                             join m in _context.Movie on r.Movie equals m
                             join a in _context.Actor on r.Actor equals a
                             where r.Actor.ID == id
                             select new LoadMovieRole {
                Actor = a.Name, Character = r.Character, Movie = m.Title
            };

            movieCastVM.roles = movieRoles;
            //Selects all movies actor is not in and creats a dropdown list
            movieCastVM.movies = new SelectList(await(from m in _context.Movie
                                                      where !movieRoles.Any(r => r.Movie == m.Title)
                                                      select m.Title).Distinct().ToListAsync());

            return(View(movieCastVM));
        }
Ejemplo n.º 3
0
        // GET: Movies/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            var movieCastVM = new MovieCastViewModel();

            if (id == null)
            {
                return(NotFound());
            }

            var movie = await _context.Movie.SingleOrDefaultAsync(m => m.ID == id);

            if (movie == null)
            {
                return(NotFound());
            }

            movieCastVM.movie = movie;
            //Query all roles for movie
            var movieRoles = from r in _context.MovieRole
                             join m in _context.Movie on r.Movie equals m
                             join a in _context.Actor on r.Actor equals a
                             where r.Movie.ID == id
                             select new LoadMovieRole {
                Actor = a.Name, Character = r.Character, Movie = m.Title
            };

            movieCastVM.roles = movieRoles;
            //Query actors not currently having a role in movie and creating a dropdown list
            movieCastVM.actors = new SelectList(await(from a in _context.Actor
                                                      where !movieRoles.Any(r => r.Actor == a.Name)
                                                      select a.Name).Distinct().ToListAsync());

            return(View(movieCastVM));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Details(int?id, string title)
        {
            var movieCastVM = new MovieCastViewModel();

            if (id == null && title == null)
            {
                return(NotFound());
            }
            else if (id == null)
            {
                id = _context.Movie.Where(m => m.Title == title).First().ID;
            }

            var movie = await _context.Movie
                        .SingleOrDefaultAsync(m => m.ID == id);

            if (movie == null)
            {
                return(NotFound());
            }

            movieCastVM.movie = movie;
            //Query all roles for movie
            movieCastVM.roles = from r in _context.MovieRole
                                join m in _context.Movie on r.Movie equals m
                                join a in _context.Actor on r.Actor equals a
                                where r.Movie.ID == id
                                select new LoadMovieRole {
                Actor = a.Name, Character = r.Character, Movie = m.Title
            };

            return(View(movieCastVM));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Delete([FromBody] MovieCastViewModel castMember)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _repository.DeleteMovieCast(Mapper.Map <MovieCast>(castMember));
            if (await _repository.SaveChangesAsync())
            {
                return(Ok($"api/moviecast/"));
            }
            return(BadRequest("Failed to save changes to the database"));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Post([FromBody] MovieCastViewModel castMember)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newCastMember = Mapper.Map <MovieCast>(castMember);

            _repository.AddMovieCast(newCastMember);
            if (await _repository.SaveChangesAsync())
            {
                return(Created($"api/moviecast/", Mapper.Map <MovieCastViewModel>(newCastMember)));
            }

            return(BadRequest("Failed to save changes to the database"));
        }