public async Task <bool> AddMovieToCategory(AddMovieToCategoryDto addMovieToCategory) { if (addMovieToCategory == null) { throw new ArgumentNullException(nameof(addMovieToCategory)); } if (addMovieToCategory.CategoryId < 1) { throw new ArgumentOutOfRangeException(nameof(addMovieToCategory.CategoryId), addMovieToCategory.CategoryId, "Category Id cannot be lower than 1."); } if (addMovieToCategory.MovieId < 1) { throw new ArgumentOutOfRangeException(nameof(addMovieToCategory.MovieId), addMovieToCategory.MovieId, "Movie Id cannot be lower than 1."); } if (!await _categoriesRepository.ExistsById(addMovieToCategory.CategoryId)) { throw new DataNotFoundException($"Category Id:{addMovieToCategory.CategoryId} doesn't exists."); } var result = await _categoriesRepository.AddMovieToCategory(addMovieToCategory.CategoryId, addMovieToCategory.MovieId); if (result == 1) { return(true); } else { return(false); } }
public async Task <IActionResult> AddMovieToCategoryAsync(AddMovieToCategoryDto addMovieToCategory) { try { await _categoriesService.AddMovieToCategory(addMovieToCategory); return(Ok()); } catch (DataNotFoundException ex) { return(NotFound(ex.Message)); } catch (ArgumentException ex) { return(BadRequest(ex.Message)); } }