| | 1 | | using Syki.Back.Features.Teacher.CreateLessonAttendance; |
| | 2 | |
|
| | 3 | | namespace Syki.Back.Features.Cross.SeedInstitutionData; |
| | 4 | |
|
| | 5 | | [CommandDescription("Realizar seed de chamadas da instituição")] |
| | 6 | | public record SeedInstitutionLessonAttendancesCommand(Guid InstitutionId) : ICommand; |
| | 7 | |
|
| 0 | 8 | | public class SeedInstitutionLessonAttendancesCommandHandler( |
| 0 | 9 | | SykiDbContext ctx, |
| 0 | 10 | | CreateLessonAttendanceService createLessonAttendanceService) : ICommandHandler<SeedInstitutionLessonAttendancesComma |
| | 11 | | { |
| | 12 | | public async Task Handle(CommandId commandId, SeedInstitutionLessonAttendancesCommand command) |
| | 13 | | { |
| 0 | 14 | | var id = command.InstitutionId; |
| | 15 | |
|
| 0 | 16 | | var classes = await ctx.Classes.AsNoTracking() |
| 0 | 17 | | .Include(c => c.Lessons) |
| 0 | 18 | | .Include(c => c.Students) |
| 0 | 19 | | .Where(c => c.InstitutionId == id) |
| 0 | 20 | | .ToListAsync(); |
| | 21 | |
|
| 0 | 22 | | var random = new Random(); |
| 0 | 23 | | var today = DateTime.UtcNow.ToDateOnly(); |
| 0 | 24 | | foreach (var @class in classes) |
| | 25 | | { |
| 0 | 26 | | foreach (var lesson in @class.Lessons.Where(l => l.Date < today)) |
| | 27 | | { |
| 0 | 28 | | var presentStudents = @class.Students.Select(s => s.Id).PickRandom(random.Next(3, 7)).ToList(); |
| 0 | 29 | | await createLessonAttendanceService.CreateWithThrowOnError(@class.TeacherId!.Value, lesson.Id, new() { P |
| | 30 | | } |
| 0 | 31 | | } |
| 0 | 32 | | } |
| | 33 | | } |