Exemplo n.º 1
0
        public async Task <IActionResult> AwardReport(int?fromyear, int?tillyear, int?page)
        {
            ViewData["header"] = "Viewing all movies with awards";
            if (fromyear != null && tillyear != null)
            {
                ViewData["header"] = "Viewing all movies with awards from " + fromyear + " till " + tillyear;
            }
            if (page != null)
            {
                ViewData["header"] += " (Page " + page + ")";
            }
            var pagedResult = await _repository.GetAwardReport(fromyear, tillyear, 25, page);

            var map = new Dictionary <int?, Dictionary <string, AwardReportViewModel> >();

            foreach (var ma in pagedResult)
            {
                if (!map.ContainsKey(ma.Movie.PublicationYear))
                {
                    map.Add(ma.Movie.PublicationYear, new Dictionary <string, AwardReportViewModel>());
                }
                if (!map[ma.Movie.PublicationYear].ContainsKey(ma.Movie.Title))
                {
                    ma.MovieAwardList.Add(ma.MovieAward);
                    map[ma.Movie.PublicationYear][ma.Movie.Title] = ma;
                }
                else
                {
                    map[ma.Movie.PublicationYear][ma.Movie.Title].MovieAwardList.Add(ma.MovieAward);
                }

                if (ma.MovieAward != null)
                {
                    if (ma.MovieAward.Result.ToLower() == "nominated")
                    {
                        map[ma.Movie.PublicationYear][ma.Movie.Title].Nominated++;
                    }
                    if (ma.MovieAward.Result.ToLower() == "won")
                    {
                        map[ma.Movie.PublicationYear][ma.Movie.Title].Won++;
                    }
                }
            }

            ViewData["Report"] = map;
            ViewData["from"]   = fromyear;
            ViewData["till"]   = tillyear;

            return(View(pagedResult));
        }