예제 #1
0
        public async Task <IActionResult> AddGenre([FromBody] GenreRequest genreRequest)
        {
            if (!await IsUserAdmin())
            {
                return(Forbid());
            }

            if (!await _videoManager.IsVideosIdValid(genreRequest.VideosId))
            {
                return(BadRequest("Videos is Invalid"));
            }

            var genre = _mapper.Map <Genre>(genreRequest);

            _genreManager.AddGenre(genre);
            await _genreManager.SaveChangesAsync();

            var response = _mapper.Map <GenreResponse>(genre);

            return(CreatedAtAction(nameof(GetGenreById), new { id = genre.Id }, response));
        }