public async Task <ActionResult <MovieResponse> > PostActor(long movieId, AddActorRequest addActorRequest)
        {
            var movie = await _context.Movies.Include(movie => movie.Comments).FirstOrDefaultAsync(movie => movie.Id == movieId);

            var        actor      = ActorMapper.mapFormAddActorRequestToActor(addActorRequest);
            var        foundActor = _context.Actor.Where(actor => actor.Name == addActorRequest.Name).ToArray();
            MovieActor movieActor = new MovieActor();

            if (foundActor.Count() == 1)
            {
                actor              = foundActor.First();
                movieActor.Actor   = actor;
                movieActor.ActorId = actor.Id;
            }
            else
            {
                movieActor.Actor   = actor;
                movieActor.ActorId = actor.Id;
            }
            movieActor.Movie   = movie;
            movieActor.MovieId = movie.Id;
            movie.Actors.Add(movieActor);
            actor.Movies.Add(movieActor);
            _context.MovieActors.Add(movieActor);
            await _context.SaveChangesAsync();

            return(Ok(MovieMapper.mapFromMovieToMovieResponse(movie)));
        }
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)));
        }