Ejemplo n.º 1
0
        public string EditMovie(CompleteMovieDto movie)
        {
            var checkExists = _movieAppRepository.GetMovie(movie.Id);

            if (checkExists == null)
            {
                return(ErrorMessages.MOVIE_DOES_NOT_EXISTS);
            }
            else
            {
                if (movie.Name != null)
                {
                    if (Utils.IsStringEmpty(movie.Name))
                    {
                        return(ErrorMessages.MOVIE_NAME_EMPTY);
                    }
                }

                if (movie.YearOfRelease > 0)
                {
                    if (movie.YearOfRelease < 1900 || movie.YearOfRelease > 2050)
                    {
                        return(ErrorMessages.MOVIE_YEAR_OF_RELEASE_SHOULD_BE_FROM_1900_2050);
                    }
                }

                if (movie.Plot != null)
                {
                    if (Utils.IsStringEmpty(movie.Plot))
                    {
                        return(ErrorMessages.MOVIE_PLOT_EMPTY);
                    }
                }

                if (movie.PosterURL != null)
                {
                    if (!Utils.IsURLValid(movie.PosterURL))
                    {
                        return(ErrorMessages.MOVIE_POSTER_INVALID_URL);
                    }
                }

                if (movie.ProducerId != null)
                {
                    var producer = _movieAppRepository.GetProducer(movie.ProducerId);
                    if (producer == null)
                    {
                        return(ErrorMessages.PRODUCER_NOT_FOUND);
                    }
                }

                if (movie.Actors != null && movie.Actors.Count != 0)
                {
                    foreach (Guid actorId in movie.Actors)
                    {
                        if (_movieAppRepository.GetActor(actorId) == null)
                        {
                            return(ErrorMessages.ACTOR_NOT_FOUND);
                        }
                    }
                }
                var editMovie = _movieAppRepository.EditMovie(movie);
                if (editMovie != null)
                {
                    return(editMovie.Id.ToString());
                }
                else
                {
                    return(ErrorMessages.SERVER_ERROR);
                }
            }
        }