| | 1 | | namespace Syki.Back.Features.Student.GetStudentExamGrades; |
| | 2 | |
|
| 2 | 3 | | public class GetStudentExamGradesService(SykiDbContext ctx) : IStudentService |
| | 4 | | { |
| | 5 | | public async Task<List<StudentExamGradeOut>> Get(Guid userId) |
| | 6 | | { |
| 2 | 7 | | var classesStudents = await ctx.ClassesStudents.AsNoTracking() |
| 2 | 8 | | .Where(x => x.SykiStudentId == userId).ToListAsync(); |
| | 9 | |
|
| 14 | 10 | | var classesIds = classesStudents.ConvertAll(x => x.ClassId); |
| 2 | 11 | | var classes = await ctx.Classes.AsNoTracking() |
| 2 | 12 | | .Include(x => x.Discipline) |
| 2 | 13 | | .Select(x => new { ClassId = x.Id, x.DisciplineId, Discipline = x.Discipline.Name }) |
| 2 | 14 | | .Where(x => classesIds.Contains(x.ClassId)) |
| 2 | 15 | | .ToListAsync(); |
| | 16 | |
|
| 14 | 17 | | var disciplinesIds = classes.ConvertAll(x => x.DisciplineId); |
| 2 | 18 | | var periods = await ctx.CourseCurriculumDisciplines.AsNoTracking() |
| 2 | 19 | | .Select(x => new { x.DisciplineId, x.Period }) |
| 2 | 20 | | .Where(x => disciplinesIds.Contains(x.DisciplineId)) |
| 2 | 21 | | .ToListAsync(); |
| | 22 | |
|
| 2 | 23 | | var examGrades = await ctx.ExamGrades.AsNoTracking() |
| 2 | 24 | | .Where(x => x.StudentId == userId).ToListAsync(); |
| | 25 | |
|
| 2 | 26 | | var result = classes.ConvertAll(c => |
| 2 | 27 | | { |
| 228 | 28 | | var disciplineExamGrades = examGrades.Where(g => g.ClassId == c.ClassId).ToList(); |
| 12 | 29 | | return new StudentExamGradeOut |
| 12 | 30 | | { |
| 12 | 31 | | ClassId = c.ClassId, |
| 12 | 32 | | Discipline = c.Discipline, |
| 12 | 33 | | AverageNote = disciplineExamGrades.GetAverageNote(), |
| 36 | 34 | | ExamGrades = disciplineExamGrades.Select(g => g.ToOut()).ToList(), |
| 42 | 35 | | Period = periods.First(p => p.DisciplineId == c.DisciplineId).Period, |
| 42 | 36 | | StudentDisciplineStatus = classesStudents.First(s => s.ClassId == c.ClassId).StudentDisciplineStatus, |
| 12 | 37 | | }; |
| 2 | 38 | | }); |
| | 39 | |
|
| 26 | 40 | | return result.OrderBy(x => x.Period).ThenBy(x => x.Discipline).ToList(); |
| 2 | 41 | | } |
| | 42 | | } |