예제 #1
0
        public async Task <bool> AppendMovie(string movieId, MovieDTO movieDTO)
        {
            if (!_repo.MovieExists(movieId))
            {
                ApiHelper.MovieObject movieObject = await ApiHelper.ApiProcessor
                                                    .LoadMovieAsync(movieId);

                if (movieObject == null)
                {
                    return(false);
                }
                MovieDTO newMovieDTO = Mapper.MovieObjectToMovieDTO(movieObject);
                if (!(await CreateMovie(newMovieDTO)))
                {
                    return(false);
                }
            }

            Movie movie = _repo.GetMovie(movieId);

            if (movie == null)
            {
                return(false);
            }

            AppendMoviesOptionalProperties(movie, movieDTO);

            _repo.UpdateMovie(movie);

            if (movieDTO.MovieActors != null)
            {
                foreach (var movieActorName in movieDTO.MovieActors)
                {
                    if (!_repo.MovieActorExists(movieId, movieActorName))
                    {
                        if (!_repo.AddMovieActor(movieId, movieActorName))
                        {
                            return(false);
                        }
                    }
                }
            }
            if (movieDTO.MovieDirectors != null)
            {
                foreach (var movieDirectorName in movieDTO.MovieDirectors)
                {
                    if (!_repo.MovieDirectorExists(movieId, movieDirectorName))
                    {
                        if (!_repo.AddMovieDirector(movieId, movieDirectorName))
                        {
                            return(false);
                        }
                    }
                }
            }
            if (movieDTO.MovieGenres != null)
            {
                foreach (var movieGenreName in movieDTO.MovieGenres)
                {
                    if (!_repo.MovieGenreExists(movieId, movieGenreName))
                    {
                        if (!_repo.AddMovieGenre(movieId, movieGenreName))
                        {
                            return(false);
                        }
                    }
                }
            }
            if (movieDTO.MovieLanguages != null)
            {
                foreach (var movieLanguageName in movieDTO.MovieLanguages)
                {
                    if (!_repo.MovieLanguageExists(movieId, movieLanguageName))
                    {
                        if (!_repo.AddMovieLanguage(movieId, movieLanguageName))
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }