예제 #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));
        }
예제 #2
0
        public IActionResult Index()
        {
            Students students = new Students();

            students.AverageGrade       = GradeList.Select(x => x.NumberGrade).Average();
            students.StudentGradeDetail = GradeList.GroupBy(x => x.LetterGrade).Select(g => new StudentGradeDetail()
            {
                LetterGrade      = g.Key,
                NumberOfStudents = g.Count()
            }).OrderBy(x => x.LetterGrade).ToList();
            students.ListOfStudents = GradeList;
            return(View(students));
        }
예제 #3
0
        /// <summary>
        /// How many students received each letter grade
        /// </summary>
        /// <returns></returns>
        private List <StudentGradeVM> GetStudentsEachLetterGrade()
        {
            var anony = GradeList.GroupBy(gl => gl.LetterGrade).Select(g => new { LetterGrade = g.Key, Count = g.Count() }).OrderBy(o => o.LetterGrade);

            List <StudentGradeVM> listvm = new List <StudentGradeVM>();

            foreach (var zz in anony.ToList())
            {
                listvm.Add(new StudentGradeVM {
                    LetterGrade = zz.LetterGrade, Count = zz.Count
                });
            }

            return(listvm);
        }