Ejemplo n.º 1
0
        public async Task <bool> UpdateTVShowAsync(UpdateTVShowInputModel input)
        {
            if (!await dbContext.TVShows.AnyAsync(tvShow => tvShow.Id == input.Id))
            {
                return(false);
            }
            if (!await dbContext.Genres.AnyAsync(genre => genre.Name == input.Genre))
            {
                return(false);
            }
            if (!await dbContext.Artists.AnyAsync(artist => artist.FullName == input.Creator))
            {
                return(false);
            }

            var genreFromDb = await dbContext.Genres.SingleOrDefaultAsync(g => g.Name == input.Genre);

            var creatorFromDb = await dbContext.Artists.SingleOrDefaultAsync(a => a.FullName == input.Creator);

            var tvShowFromDb = await dbContext.TVShows.FindAsync(input.Id);

            tvShowFromDb.Name           = input.Name;
            tvShowFromDb.Genre          = genreFromDb;
            tvShowFromDb.Creator        = creatorFromDb;
            tvShowFromDb.Description    = input.Description;
            tvShowFromDb.CoverImageLink = input.CoverImageLink;
            tvShowFromDb.TrailerLink    = input.TrailerLink;

            dbContext.Update(tvShowFromDb);
            await dbContext.SaveChangesAsync();

            return(true);
        }
        public async Task <IActionResult> Update(UpdateTVShowInputModel input)
        {
            if (!ModelState.IsValid)
            {
                return(View(input));
            }

            if (!await tvShowService.UpdateTVShowAsync(input))
            {
                return(View(input));
            }

            return(Redirect(redirectTVShowDetails + input.Id));
        }