| | 1 | | namespace Syki.Back.Features.Academic.GetAcademicClass; |
| | 2 | |
|
| 10 | 3 | | public class GetAcademicClassService(SykiDbContext ctx) : IAcademicService |
| | 4 | | { |
| | 5 | | public async Task<OneOf<GetAcademicClassOut, SykiError>> Get(Guid institutionId, Guid id) |
| | 6 | | { |
| 10 | 7 | | var @class = await ctx.Classes.AsNoTracking() |
| 10 | 8 | | .Include(t => t.Discipline) |
| 10 | 9 | | .Include(t => t.Teacher) |
| 10 | 10 | | .Include(t => t.Schedules) |
| 10 | 11 | | .Include(t => t.Lessons) |
| 10 | 12 | | .ThenInclude(l => l.Attendances) |
| 10 | 13 | | .Include(t => t.Students) |
| 10 | 14 | | .Include(t => t.ExamGrades) |
| 10 | 15 | | .Where(c => c.InstitutionId == institutionId && c.Id == id) |
| 10 | 16 | | .FirstOrDefaultAsync(); |
| | 17 | |
|
| 11 | 18 | | if (@class == null) return new ClassNotFound(); |
| | 19 | |
|
| 9 | 20 | | var count = await ctx.ClassesStudents.Where(x => x.ClassId == id).CountAsync(); |
| 9 | 21 | | @class.SetFillRatio(count); |
| | 22 | |
|
| 9 | 23 | | var period = await ctx.EnrollmentPeriods.AsNoTracking().Where(x => x.InstitutionId == institutionId && x.Id == @ |
| 9 | 24 | | if (@class.Status == ClassStatus.OnEnrollment && period?.EndAt < DateTime.Now.ToDateOnly()) |
| | 25 | | { |
| 1 | 26 | | @class.Status = ClassStatus.AwaitingStart; |
| | 27 | | } |
| | 28 | |
|
| 9 | 29 | | return @class.ToGetAcademicClassOut(); |
| 10 | 30 | | } |
| | 31 | | } |