Exemplo n.º 1
0
        public async Task <IActionResult> ActorToMovie(int id, int actorId)
        {
            var actor = await _repo.GetActor(actorId);

            var movie = await _repo.GetMovie(id);

            var actorMovie = await _repo.GetActorMovieRelation(actorId, id);

            if (actorMovie != null)
            {
                return(BadRequest("This actor is already in that movie"));
            }

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

            if (movie.Year < actor.BirthDay.Year)
            {
                return(BadRequest("The actor was born later than the movie was made"));
            }

            actorMovie = new ActorMovie
            {
                ActorId = actorId,
                MovieId = id
            };

            _repo.Add(actorMovie);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to add actor to movie"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetActor(int id)
        {
            var actor = await _repo.GetActor(id);

            return(Ok(actor));
        }