| | 1 | | namespace Syki.Back.Features.Academic.ReleaseClassesForEnrollment; |
| | 2 | |
|
| 316 | 3 | | public class ReleaseClassesForEnrollmentService(SykiDbContext ctx) : IAcademicService |
| | 4 | | { |
| | 5 | | public async Task<OneOf<SykiSuccess, SykiError>> Release(Guid institutionId, ReleaseClassesForEnrollmentIn data) |
| | 6 | | { |
| 50 | 7 | | var classes = await ctx.Classes |
| 50 | 8 | | .Where(c => c.InstitutionId == institutionId && data.Classes.Contains(c.Id)) |
| 50 | 9 | | .ToListAsync(); |
| | 10 | |
|
| 50 | 11 | | var today = DateTime.Now.ToDateOnly(); |
| 50 | 12 | | var periods = await ctx.EnrollmentPeriods.AsNoTracking().Where(x => x.InstitutionId == institutionId).ToListAsyn |
| 444 | 13 | | foreach (var @class in classes) |
| | 14 | | { |
| 346 | 15 | | var period = periods.FirstOrDefault(x => x.Id == @class.PeriodId); |
| 176 | 16 | | if (period == null) return new EnrollmentPeriodNotFound(); |
| 173 | 17 | | if (today < period.StartAt) return new EnrollmentPeriodNotStarted(); |
| 172 | 18 | | if (today > period.EndAt) return new EnrollmentPeriodFinalized(); |
| | 19 | | } |
| | 20 | |
|
| 216 | 21 | | var statusOk = classes.All(x => x.Status == ClassStatus.OnPreEnrollment); |
| 47 | 22 | | if (!statusOk) return new AllClassesMustHaveOnPreEnrollmentStatus(); |
| | 23 | |
|
| 214 | 24 | | classes.ForEach(c => c.Status = ClassStatus.OnEnrollment); |
| | 25 | |
|
| 45 | 26 | | await ctx.SaveChangesAsync(); |
| | 27 | |
|
| 45 | 28 | | return new SykiSuccess(); |
| 50 | 29 | | } |
| | 30 | | } |