public ViewResult Index(string Slug) { var series = _context.Series.FirstOrDefault(s => s.Slug == Slug); SeasonIndexViewModel seasonIndexViewModel = new SeasonIndexViewModel { Series = series, Seasons = _context.Seasons.Where(s => s.SeriesId == series.Id).ToList() }; return(View(seasonIndexViewModel)); }
// GET: Seasons public IActionResult Index() { if (!User.IsInRole("Admin")) { return(RedirectToAction("Index", "Home")); } var seasons = _seasonRepository.GetSeasons(); var model = new SeasonIndexViewModel { Seasons = seasons.ToList(), StatusMessage = StatusMessage }; return(View(model)); }
// GET: Seasons public async Task <IActionResult> Index(long?seriesId) { var seasons = await _context.Seasons.Include(s => s.Series) .Include(s => s.Episodes) .Where(x => x.SeriesId == seriesId) .ToListAsync(); var viewModel = new SeasonIndexListViewModel { SeriesId = seriesId, ViewModels = new List <SeasonIndexViewModel>() }; List <DataPointLine> LineChartDataPoints = new List <DataPointLine>(); foreach (var season in seasons) { var seasonViewModel = new SeasonIndexViewModel { Id = season.Id, Name = season.Name, SeasonNumber = season.SeasonNumber, NumberOfEpisodes = season.NumberOfEpisodes, }; if (season.AiredFrom != null) { seasonViewModel.AiredFrom = season.AiredFrom.Value.ToString("dd MMMM yyyy"); } viewModel.ViewModels.Add(seasonViewModel); var meanRating = season.Episodes.Sum(x => x.UserRating) / season.Episodes.Count(); var dataPoint = new DataPointLine(Convert.ToDouble(meanRating), "S" + season.SeasonNumber.ToString()); LineChartDataPoints.Add(dataPoint); } ViewBag.DataPointsLine = JsonConvert.SerializeObject(LineChartDataPoints); return(View(viewModel)); }