| | 1 | | namespace Syki.Back.Features.Teacher.GetTeacherLessonAttendances; |
| | 2 | |
|
| 0 | 3 | | public class GetTeacherLessonAttendancesService(SykiDbContext ctx) : ITeacherService |
| | 4 | | { |
| | 5 | | public async Task<OneOf<List<GetTeacherLessonAttendanceOut>, SykiError>> Get(Guid institutionId, Guid userId, Guid l |
| | 6 | | { |
| 0 | 7 | | var lesson = await ctx.Lessons.FirstOrDefaultAsync(x => x.Id == lessonId); |
| 0 | 8 | | if (lesson == null) return new LessonNotFound(); |
| | 9 | |
|
| 0 | 10 | | var @class = await ctx.Classes.AsNoTracking() |
| 0 | 11 | | .Include(x => x.Students) |
| 0 | 12 | | .Where(t => t.InstitutionId == institutionId && t.TeacherId == userId && t.Id == lesson.ClassId) |
| 0 | 13 | | .FirstOrDefaultAsync(); |
| | 14 | |
|
| 0 | 15 | | if (@class == null) return new ClassNotFound(); |
| | 16 | |
|
| 0 | 17 | | var attendances = await ctx.Attendances.Where(x => x.LessonId == lessonId).ToListAsync(); |
| 0 | 18 | | return @class.Students.OrderBy(s => s.Name).Select(s => |
| 0 | 19 | | { |
| 0 | 20 | | var value = attendances.FirstOrDefault(a => a.StudentId == s.Id); |
| 0 | 21 | | if (value != null) return value.ToOut(s.Name); |
| 0 | 22 | | return new() { LessonId = lessonId, StudentId = s.Id, StudentName = s.Name }; |
| 0 | 23 | | }).ToList(); |
| 0 | 24 | | } |
| | 25 | | } |