| | 1 | | namespace Syki.Back.Features.Student.GetStudentDisciplines; |
| | 2 | |
|
| 1 | 3 | | public class GetStudentDisciplinesService(SykiDbContext ctx) : IStudentService |
| | 4 | | { |
| | 5 | | public async Task<List<DisciplineOut>> Get(Guid userId, Guid courseCurriculumId) |
| | 6 | | { |
| 1 | 7 | | var courseCurriculum = await ctx.CourseCurriculums.AsNoTracking() |
| 1 | 8 | | .Include(g => g.Course) |
| 1 | 9 | | .Include(g => g.Disciplines) |
| 1 | 10 | | .Include(g => g.Links) |
| 1 | 11 | | .FirstAsync(g => g.Id == courseCurriculumId); |
| | 12 | |
|
| 4 | 13 | | var response = courseCurriculum.ToOut().Disciplines.OrderBy(d => d.Period).ToList(); |
| | 14 | |
|
| 1 | 15 | | var studentClassesStatus = await ctx.ClassesStudents.AsNoTracking() |
| 1 | 16 | | .Where(x => x.SykiStudentId == userId) |
| 1 | 17 | | .ToListAsync(); |
| | 18 | |
|
| 4 | 19 | | var ids = courseCurriculum.Disciplines.ConvertAll(d => d.Id); |
| 1 | 20 | | var classes = await ctx.Classes.Where(t => ids.Contains(t.DisciplineId)) |
| 1 | 21 | | .Select(x => new { x.Id, x.DisciplineId }).ToListAsync(); |
| | 22 | |
|
| 1 | 23 | | response.ForEach(r => |
| 1 | 24 | | { |
| 3 | 25 | | var classId = classes.FirstOrDefault(x => x.DisciplineId == r.Id)?.Id; |
| 3 | 26 | | r.StudentDisciplineStatus = studentClassesStatus.FirstOrDefault(x => x.ClassId == classId)?.StudentDisciplin |
| 4 | 27 | | }); |
| | 28 | |
|
| 4 | 29 | | return response.OrderBy(x => x.Name).ToList(); |
| 1 | 30 | | } |
| | 31 | | } |