public async Task <bool> UpdateMovie(string movieId, MovieDTO movieDTO) { if (movieDTO.ImdbId != null && movieDTO.ImdbId != movieId) { return(false); } if (!_repo.MovieExists(movieId)) { return(await CreateMovie(movieDTO)); } Movie movie = _repo.GetMovie(movieId); movie.Title = movieDTO.Title; movie.ReleaseCountry = movieDTO.ReleaseCountry; movie.RuntimeMinutes = movieDTO.RuntimeMinutes; movie.Plot = movieDTO.Plot; movie.PosterUrl = movieDTO.PosterURL; if (String.IsNullOrEmpty(movieDTO.RatingName)) { movie.RatingId = null; } else { if (!_repo.RatingExists(movieDTO.RatingName)) { Rating newRating = new Rating(); newRating.RatingName = movieDTO.RatingName; _repo.AddRating(newRating); } movie.RatingId = _repo.GetRating(movieDTO.RatingName).RatingId; } if (String.IsNullOrEmpty(movieDTO.ReleaseDate)) { movie.ReleaseDate = null; movie.IsReleased = null; } else { movie.ReleaseDate = DateTime.ParseExact(movieDTO.ReleaseDate, "yyyy-MM-dd", CultureInfo.InvariantCulture); movie.IsReleased = true; } _repo.UpdateMovie(movie); _repo.ClearMovieActors(movieId); if (movieDTO.MovieActors != null) { foreach (var movieActorName in movieDTO.MovieActors) { if (!_repo.AddMovieActor(movieId, movieActorName)) { return(false); } } } _repo.ClearMovieDirectors(movieId); if (movieDTO.MovieDirectors != null) { foreach (var movieDirectorName in movieDTO.MovieDirectors) { if (!_repo.AddMovieDirector(movieId, movieDirectorName)) { return(false); } } } _repo.ClearMovieGenres(movieId); if (movieDTO.MovieGenres != null) { foreach (var movieGenreName in movieDTO.MovieGenres) { if (!_repo.AddMovieGenre(movieId, movieGenreName)) { return(false); } } } _repo.ClearMovieLanguages(movieId); if (movieDTO.MovieLanguages != null) { foreach (var movieLanguageName in movieDTO.MovieLanguages) { if (!_repo.AddMovieLanguage(movieId, movieLanguageName)) { return(false); } } } return(true); }