| | 1 | | namespace Syki.Back.Features.Student.GetStudentEnrollmentClasses; |
| | 2 | |
|
| 7 | 3 | | public class GetStudentEnrollmentClassesService(SykiDbContext ctx) : IStudentService |
| | 4 | | { |
| | 5 | | public async Task<List<EnrollmentClassOut>> Get(Guid institutionId, Guid userId, Guid courseCurriculumId) |
| | 6 | | { |
| 7 | 7 | | var today = DateOnly.FromDateTime(DateTime.Now); |
| 7 | 8 | | var enrollmentPeriod = await ctx.EnrollmentPeriods.AsNoTracking() |
| 7 | 9 | | .Where(p => p.InstitutionId == institutionId && p.StartAt <= today && p.EndAt >= today) |
| 7 | 10 | | .FirstOrDefaultAsync(); |
| | 11 | |
|
| 7 | 12 | | if (enrollmentPeriod == null) |
| 4 | 13 | | return []; |
| | 14 | |
|
| 3 | 15 | | var courseCurriculum = await ctx.CourseCurriculums.Where(g => g.Id == courseCurriculumId).AsNoTracking() |
| 3 | 16 | | .Include(g => g.Links) |
| 3 | 17 | | .FirstAsync(); |
| 39 | 18 | | var ids = courseCurriculum.Links.ConvertAll(d => d.DisciplineId); |
| | 19 | |
|
| 3 | 20 | | var classes = await ctx.Classes.AsNoTracking() |
| 3 | 21 | | .Include(t => t.Discipline) |
| 3 | 22 | | .Include(t => t.Schedules) |
| 3 | 23 | | .Include(t => t.Teacher) |
| 3 | 24 | | .Where(t => t.InstitutionId == institutionId && t.PeriodId == enrollmentPeriod.Id && t.Status == ClassStatus |
| 3 | 25 | | .ToListAsync(); |
| | 26 | |
|
| 3 | 27 | | var selecteds = await ctx.ClassesStudents.Where(x => x.SykiStudentId == userId).Select(x => x.ClassId).ToListAsy |
| | 28 | |
|
| 3 | 29 | | var response = classes.ConvertAll(t => |
| 3 | 30 | | { |
| 33 | 31 | | var link = courseCurriculum.Links.First(v => v.DisciplineId == t.DisciplineId); |
| 4 | 32 | | return new EnrollmentClassOut |
| 4 | 33 | | { |
| 4 | 34 | | Id = t.Id, |
| 4 | 35 | | Discipline = t.Discipline.Name, |
| 4 | 36 | | Period = link.Period, |
| 4 | 37 | | Credits = link.Credits, |
| 4 | 38 | | Workload = link.Workload, |
| 4 | 39 | | Teacher = t.Teacher.Name, |
| 4 | 40 | | Schedules = t.Schedules.ConvertAll(h => h.ToOut()), |
| 4 | 41 | | IsSelected = selecteds.Contains(t.Id), |
| 4 | 42 | | }; |
| 3 | 43 | | }); |
| | 44 | |
|
| 7 | 45 | | return response.OrderBy(t => t.Period).ToList(); |
| 7 | 46 | | } |
| | 47 | | } |