Exemplo n.º 1
0
        public async Task <IActionResult> UpdateGenres([FromBody] MovieGenrePostModel genres)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var models = new List <MovieGenre>();

            if (genres.Genres != null)
            {
                foreach (var g in genres.Genres)
                {
                    var m = new MovieGenreViewModel()
                    {
                        GenreName = g, MovieId = genres.MovieId
                    };
                    models.Add(Mapper.Map <MovieGenre>(m));
                }
            }

            _repository.AddGenres(genres.MovieId, models);
            if (await _repository.SaveChangesAsync())
            {
                return(Ok("Updated genres"));
            }

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