Beispiel #1
0
        public async Task UpdateAsync(int id, MovieRequest updateMovie)
        {
            var movie = await _dbContext.Movies.FirstOrDefaultAsync(x => x.Id == id);

            if (movie == null)
            {
                throw new Exception($"Movie with id: {id} not found.");
            }

            if (updateMovie.Title != null)
            {
                movie.SetTitle(updateMovie.Title);
            }
            if (updateMovie.TrailerPath != null)
            {
                movie.SetTrailerPath(updateMovie.TrailerPath);
            }
            if (updateMovie.ProductionDate != null)
            {
                movie.SetProductionDate(updateMovie.ProductionDate);
            }
            if (updateMovie.PosterPath != null)
            {
                movie.SetPosterPath(updateMovie.PosterPath);
            }
            if (updateMovie.BackgroundPath != null)
            {
                movie.SetBackgroundPath(updateMovie.BackgroundPath);
            }
            movie.SetCategory(updateMovie.Category);
            if (updateMovie.Description != null)
            {
                movie.SetDescription(updateMovie.Description);
            }
            if (updateMovie.ProductionDate.HasValue)
            {
                movie.SetProductionDate(updateMovie.ProductionDate.Value);
            }
            if (updateMovie.Duration.HasValue)
            {
                movie.SetDuration(updateMovie.Duration.Value);
            }
            if (updateMovie.MinimalAge.HasValue)
            {
                movie.SetMinimalAge(updateMovie.MinimalAge.Value);
            }
            _dbContext.Update(movie);
            await _dbContext.SaveChangesAsync();
        }