| | | 1 | | namespace Syki.Back.Features.Cross.GetHomeStats; |
| | | 2 | | |
| | 0 | 3 | | public class GetHomeStatsService(SykiDbContext ctx) : ISykiService |
| | | 4 | | { |
| | | 5 | | public async Task<GetHomeStatsOut> Get() |
| | | 6 | | { |
| | 0 | 7 | | var institutionId = ctx.RequestUser.InstitutionId; |
| | | 8 | | |
| | 0 | 9 | | var enrolledStudents = await ctx.StudentCourseEnrollments.AsNoTracking() |
| | 0 | 10 | | .Where(e => e.LeftAt == null && ctx.Students.Any(s => s.Id == e.StudentId && s.InstitutionId == institutionI |
| | 0 | 11 | | .CountAsync(); |
| | | 12 | | |
| | 0 | 13 | | var activeTeachers = await ctx.Teachers.AsNoTracking() |
| | 0 | 14 | | .Where(t => t.InstitutionId == institutionId) |
| | 0 | 15 | | .CountAsync(); |
| | | 16 | | |
| | 0 | 17 | | var offeredCourses = await ctx.CourseOfferings.AsNoTracking() |
| | 0 | 18 | | .Where(o => o.InstitutionId == institutionId) |
| | 0 | 19 | | .CountAsync(); |
| | | 20 | | |
| | 0 | 21 | | var registeredDisciplines = await ctx.Disciplines.AsNoTracking() |
| | 0 | 22 | | .Where(d => d.InstitutionId == institutionId) |
| | 0 | 23 | | .CountAsync(); |
| | | 24 | | |
| | 0 | 25 | | return new GetHomeStatsOut |
| | 0 | 26 | | { |
| | 0 | 27 | | EnrolledStudents = enrolledStudents, |
| | 0 | 28 | | ActiveTeachers = activeTeachers, |
| | 0 | 29 | | OfferedCourses = offeredCourses, |
| | 0 | 30 | | RegisteredDisciplines = registeredDisciplines, |
| | 0 | 31 | | }; |
| | 0 | 32 | | } |
| | | 33 | | } |