Ejemplo n.º 1
0
        public IActionResult Index()
        {
            //This is the average via simple average lambda
            double averageGrade = GradeList.Average(x => x.NumberGrade);

            //Simple Group by into anonymous type for aggregate
            var groupedGrades = GradeList
                                .GroupBy(x => x.LetterGrade)
                                .Select(g => new
            {
                g.Key,
                Count = g.Count()
            })
                                .ToList()
                                .OrderBy(o => o.Key);

            var aggregateGrades = new Dictionary <string, int>();

            foreach (var g in groupedGrades)
            {
                aggregateGrades.Add(g.Key, g.Count);
            }

            ViewBag.AverageGrade = averageGrade;
            ViewBag.GroupList    = aggregateGrades;

            return(View(GradeList));
        }