public async Task <GetActorMovieModel> PostActorMovie(PostActorMovieModel postActorMovieModel) { Actor actor = await _context.Actors.FirstOrDefaultAsync(x => x.Id == postActorMovieModel.ActorId); if (actor == null) { throw new EntityException("Actor not found", this.GetType().Name, "PostActorMovie", "404"); } Movie movie = await _context.Movies.FirstOrDefaultAsync(x => x.Id == postActorMovieModel.MovieId); if (movie == null) { throw new EntityException("Movie not found", this.GetType().Name, "PostActorMovie", "404"); } try { EntityEntry <ActorMovie> result = await _context.ActorMovies.AddAsync(new ActorMovie { ActorId = postActorMovieModel.ActorId, Actor = actor, MovieId = postActorMovieModel.MovieId, Movie = movie }); await _context.SaveChangesAsync(); return(await GetActorMovie(result.Entity.Id.ToString())); } catch (Exception e) { throw new DatabaseException(e.InnerException.Message, this.GetType().Name, "PostActorMovie", "400"); } }
public async Task <ActionResult <GetActorMovieModel> > PostActorMovie(PostActorMovieModel postActorMovieModel) { try { GetActorMovieModel getActorMovieModel = await _actorMovieRepository.PostActorMovie(postActorMovieModel); return(CreatedAtAction(nameof(GetActorMovie), new { id = getActorMovieModel.Id }, getActorMovieModel)); } catch (DatabaseException e) { return(BadRequest(e.MovieMindError)); } }