| | 1 | | namespace Syki.Back.Features.Student.GetStudentFrequencies; |
| | 2 | |
|
| 3 | 3 | | public class GetStudentFrequenciesService(SykiDbContext ctx) : IStudentService |
| | 4 | | { |
| | 5 | | public async Task<OneOf<List<GetStudentFrequenciesOut>, ErrorOut>> Get(Guid userId, Guid courseCurriculumId) |
| | 6 | | { |
| 3 | 7 | | var attendances = await ctx.Attendances.AsNoTracking().Where(x => x.StudentId == userId).ToListAsync(); |
| | 8 | |
|
| 16 | 9 | | var classIds = attendances.Select(x => x.ClassId).Distinct(); |
| 3 | 10 | | var classes = await ctx.Classes.AsNoTracking() |
| 3 | 11 | | .Include(g => g.Discipline) |
| 3 | 12 | | .Where(x => classIds.Contains(x.Id)) |
| 3 | 13 | | .ToListAsync(); |
| | 14 | |
|
| 10 | 15 | | var disciplineIds = classes.Select(x => x.DisciplineId); |
| 3 | 16 | | var disciplines = await ctx.CourseCurriculumDisciplines.AsNoTracking() |
| 3 | 17 | | .Where(x => x.CourseCurriculumId == courseCurriculumId && disciplineIds.Contains(x.DisciplineId)) |
| 3 | 18 | | .ToListAsync(); |
| | 19 | |
|
| 3 | 20 | | var classesStudents = await ctx.ClassesStudents.AsNoTracking() |
| 3 | 21 | | .Where(x => x.SykiStudentId == userId).ToListAsync(); |
| | 22 | |
|
| 3 | 23 | | var result = new List<GetStudentFrequenciesOut>(); |
| 20 | 24 | | foreach (var item in classes) |
| | 25 | | { |
| 29 | 26 | | var period = disciplines.First(x => x.DisciplineId == item.DisciplineId).Period.ToString(); |
| 80 | 27 | | var lessons = attendances.Count(x => x.ClassId == item.Id); |
| 80 | 28 | | var presences = attendances.Count(x => x.ClassId == item.Id && x.Present); |
| 29 | 29 | | var status = classesStudents.First(s => s.ClassId == item.Id).StudentDisciplineStatus; |
| 7 | 30 | | result.Add(new(item.Discipline.Name, period, lessons, presences, status)); |
| | 31 | | } |
| | 32 | |
|
| 17 | 33 | | return result.OrderBy(x => x.Period).ThenBy(x => x.Name).ToList(); |
| 3 | 34 | | } |
| | 35 | | } |