| | 1 | | namespace Syki.Back.Features.Academic.UpdateEnrollmentPeriod; |
| | 2 | |
|
| 100 | 3 | | public class UpdateEnrollmentPeriodService(SykiDbContext ctx, HybridCache cache) : IAcademicService |
| | 4 | | { |
| | 5 | | public async Task<OneOf<EnrollmentPeriodOut, SykiError>> Update(Guid institutionId, string id, UpdateEnrollmentPerio |
| | 6 | | { |
| 100 | 7 | | var academicPeriodExists = await ctx.AcademicPeriodExists(institutionId, id); |
| 102 | 8 | | if (!academicPeriodExists) return new AcademicPeriodNotFound(); |
| | 9 | |
|
| 98 | 10 | | var period = await ctx.EnrollmentPeriods.FirstOrDefaultAsync(x => x.InstitutionId == institutionId && x.Id == id |
| 100 | 11 | | if (period == null) return new EnrollmentPeriodNotFound(); |
| | 12 | |
|
| 96 | 13 | | var result = period.Update(data.StartAt, data.EndAt); |
| | 14 | |
|
| 100 | 15 | | if (result.IsError) return result.Error; |
| | 16 | |
|
| 92 | 17 | | await ctx.SaveChangesAsync(); |
| | 18 | |
|
| 92 | 19 | | await cache.RemoveAsync($"enrollmentPeriods:{institutionId}"); |
| | 20 | |
|
| 92 | 21 | | return period.ToOut(); |
| 100 | 22 | | } |
| | 23 | |
|
| | 24 | | public async Task UpdateWithThrowOnError(Guid institutionId, string id, UpdateEnrollmentPeriodIn data) |
| | 25 | | { |
| 0 | 26 | | (await Update(institutionId, id, data)).ThrowOnError(); |
| 0 | 27 | | } |
| | 28 | | } |