Example #1
0
        public async Task <bool> UpdateSeasonAsync(UpdateSeasonInputModel input)
        {
            if (!await dbContext.Seasons.AnyAsync(season => season.Id == input.Id))
            {
                return(false);
            }
            if (!await dbContext.TVShows.AnyAsync(tvShow => tvShow.Name == input.TVShow))
            {
                return(false);
            }

            var tvShowFromDb = await dbContext.TVShows.SingleOrDefaultAsync(tvShow => tvShow.Name == input.TVShow);

            var seasonFromDb = await dbContext.Seasons.SingleOrDefaultAsync(season => season.Id == input.Id);

            if (tvShowFromDb != seasonFromDb.TVShow)
            {
                seasonFromDb.SeasonNumber = tvShowFromDb.Seasons.Count() + 1;
            }
            seasonFromDb.TVShow           = tvShowFromDb;
            seasonFromDb.ReleaseDate      = input.ReleaseDate;
            seasonFromDb.Episodes         = input.Episodes;
            seasonFromDb.LengthPerEpisode = input.LengthPerEpisode;

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

            return(true);
        }
        public ActionResult Edit(long id)
        {
            var season = _seasonRepository.GetSeasonById(id);
            var updateSeasonOutputModel = new UpdateSeasonInputModel();

            updateSeasonOutputModel.Type = season.Type;
            ViewBag.SeasonId             = id;

            return(View("UpdateSeason", updateSeasonOutputModel));
        }
        public ActionResult Edit(int id, UpdateSeasonInputModel model)
        {
            if (ModelState.IsValid)
            {
                var season = _seasonRepository.GetSeasonById(id);
                season.UpdateSeasonType(model.Type);
                _seasonRepository.UpdateSeason();

                return(RedirectToAction(nameof(Index)));
            }

            return(View());
        }
        public async Task <IActionResult> UpdateSeason(UpdateSeasonInputModel input)
        {
            if (!ModelState.IsValid)
            {
                return(View(input));
            }

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

            return(Redirect(redirectTVShowsAllAndOrder));
        }