public async Task <IActionResult> AddSeason(AddSeasonInputModel input) { if (!ModelState.IsValid) { return(View(input)); } if (!await tvShowService.AddSeasonToTVShowAsync(input)) { return(View(input)); } return(Redirect(redirectTVShowsAllAndOrder)); }
public async Task <bool> AddSeasonToTVShowAsync(AddSeasonInputModel input) { if (!await dbContext.TVShows.AnyAsync(tvShow => tvShow.Name == input.TVShow)) { return(false); } var tvShowFromDb = await dbContext.TVShows.SingleOrDefaultAsync(t => t.Name == input.TVShow); var seasonForDb = mapper.Map <AddSeasonInputModel, Season>(input); seasonForDb.TVShow = tvShowFromDb; seasonForDb.SeasonNumber = tvShowFromDb.Seasons.Count() + 1; await dbContext.Seasons.AddAsync(seasonForDb); await dbContext.SaveChangesAsync(); return(true); }