Exemple #1
0
        public IEnumerable <GradesPerSemester> GetStudentsGradesPerSemester()
        {
            var finalGrades = finalGradeRepository.Query().Include(x => x.Course)
                              .Include(x => x.Course.Status)
                              .OrderBy(x => x.Course.Semester)
                              .GroupBy(x => x.StudentId);
            var result = new List <GradesPerSemester>();

            foreach (var student in finalGrades)
            {
                var averages = CalculateAverage(student);
                var response = new GradesPerSemester()
                {
                    Semester1 = decimal.Round(averages.FirstOrDefault(x => x.Semester == 1).Average.Value, 2, MidpointRounding.AwayFromZero),
                    Semester2 = decimal.Round(averages.FirstOrDefault(x => x.Semester == 2).Average.Value, 2, MidpointRounding.AwayFromZero),
                    Semester3 = decimal.Round(averages.FirstOrDefault(x => x.Semester == 3).Average.Value, 2, MidpointRounding.AwayFromZero),
                    Semester4 = decimal.Round(averages.FirstOrDefault(x => x.Semester == 4).Average.Value, 2, MidpointRounding.AwayFromZero),
                    Semester5 = decimal.Round(averages.FirstOrDefault(x => x.Semester == 5).Average.Value, 2, MidpointRounding.AwayFromZero),
                    Semester6 = decimal.Round(averages.FirstOrDefault(x => x.Semester == 6).Average.Value, 2, MidpointRounding.AwayFromZero),
                };
                result.Add(response);
            }

            return(result);
        }
Exemple #2
0
        public GradesPerSemester GetCurrentUserGradesPerSemester(int userId)
        {
            var averages = CalculateStudentMeans(userId);

            if (averages is null || averages.Count() == 0)
            {
                return(new GradesPerSemester());
            }

            var result = new GradesPerSemester()
            {
                Semester1 = decimal.Round(averages.FirstOrDefault(x => x.Semester == 1).Average.Value, 2, MidpointRounding.AwayFromZero),
                Semester2 = decimal.Round(averages.FirstOrDefault(x => x.Semester == 2).Average.Value, 2, MidpointRounding.AwayFromZero),
                Semester3 = decimal.Round(averages.FirstOrDefault(x => x.Semester == 3).Average.Value, 2, MidpointRounding.AwayFromZero),
                Semester4 = decimal.Round(averages.FirstOrDefault(x => x.Semester == 4).Average.Value, 2, MidpointRounding.AwayFromZero),
                Semester5 = decimal.Round(averages.FirstOrDefault(x => x.Semester == 5).Average.Value, 2, MidpointRounding.AwayFromZero),
                Semester6 = decimal.Round(averages.FirstOrDefault(x => x.Semester == 6).Average.Value, 2, MidpointRounding.AwayFromZero),
            };

            return(result);
        }