public JsonResult AddMovieGenre(int movieId, int genreId) { var request = new AddMovieGenreRequest {Id = movieId, GenreId = genreId}; AddMovieGenreResponse response = _movieService.AddMovieGenre(request); return Json(response); }
/// <summary> /// Add genre to specified movie /// </summary> /// <param name="request"></param> /// <returns></returns> public AddMovieGenreResponse AddMovieGenre(AddMovieGenreRequest request) { var response = new AddMovieGenreResponse(); if (request.Id > 0 && request.GenreId > 0) { Movie movie = _movieRepository.FindBy(request.Id) ?? new Movie(); if (!IsGenreInList(movie.Genres, request.GenreId)) { Genre genre = _genreRepository.FindBy(request.GenreId); movie.Genres.Add(genre); _movieRepository.Save(movie); _uow.Commit(); response.Successful = true; response.GenreName = genre.Name; } else { response.Successful = false; response.Message = "Genre is already assign to movie"; } } else response.Successful = false; return response; }