コード例 #1
0
        public JsonResult AddMovieGenre(int movieId, int genreId)
        {
            var request = new AddMovieGenreRequest {Id = movieId, GenreId = genreId};
            AddMovieGenreResponse response = _movieService.AddMovieGenre(request);

            return Json(response);
        }
コード例 #2
0
ファイル: MovieService.cs プロジェクト: CWharton/muvykive
        /// <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;
        }