Beispiel #1
0
        public async Task <ActionResult <ActorResponse> > DeleteActor(long actorId)
        {
            var actor = _context.Actor.Include(actor => actor.Movies).FirstOrDefault(actor => actor.Id == actorId);

            _context.Actor.Remove(actor);
            await _context.SaveChangesAsync();

            return(Ok(ActorMapper.mapFormActorToActorResponse(actor)));
        }
Beispiel #2
0
        public async Task <ActionResult <ActorResponse> > PostActor(AddActorRequest addActorRequest)
        {
            Actor actor = ActorMapper.mapFormAddActorRequestToActor(addActorRequest);

            _context.Actor.Add(actor);
            await _context.SaveChangesAsync();

            return(Ok(ActorMapper.mapFormActorToActorResponse(actor)));
        }
        public async Task <ActionResult <List <ActorResponse> > > GetActors(long movieId)
        {
            var movie = await _context.Movies
                        .Include(movie => movie.Comments)
                        .Include(movie => movie.Actors)
                        .FirstOrDefaultAsync(movie => movie.Id == movieId);

            var movieActors = await _context.MovieActors
                              .Where(movieActor => movieActor.MovieId == movieId)
                              .Include(movie => movie.Movie)
                              .Include(actor => actor.Actor)
                              .ToListAsync();

            var actors = new List <Actor>();

            foreach (var movieActor in movieActors)
            {
                actors.Add(movieActor.Actor);
            }

            return(Ok(ActorMapper.mapFormActorToActorResponse(actors)));
        }