| | 1 | | using Syki.Back.Features.Academic.CreateNotification; |
| | 2 | |
|
| | 3 | | namespace Syki.Back.Features.Teacher.CreateClassActivity; |
| | 4 | |
|
| | 5 | | [CommandDescription("Criar notificação de nova atividade")] |
| | 6 | | public record CreateNewClassActivityNotificationCommand(Guid ClassActivityId) : ICommand; |
| | 7 | |
|
| 144 | 8 | | public class CreateNewClassActivityNotificationCommandHandler(SykiDbContext ctx) : ICommandHandler<CreateNewClassActivit |
| | 9 | | { |
| | 10 | | public async Task Handle(CommandId commandId, CreateNewClassActivityNotificationCommand command) |
| | 11 | | { |
| 144 | 12 | | var activity = await ctx.ClassActivities |
| 144 | 13 | | .Where(x => x.Id == command.ClassActivityId).Select(x => new { x.ClassId, x.Title }).FirstAsync(); |
| | 14 | |
|
| 144 | 15 | | var @class = await ctx.Classes.AsNoTracking() |
| 144 | 16 | | .Include(x => x.Discipline) |
| 144 | 17 | | .FirstAsync(x => x.Id == activity.ClassId); |
| | 18 | |
|
| 144 | 19 | | var students = await ctx.ClassesStudents |
| 144 | 20 | | .Where(x => x.ClassId == @class.Id) |
| 144 | 21 | | .Select(x => new { Id = x.SykiStudentId }) |
| 144 | 22 | | .ToListAsync(); |
| | 23 | |
|
| 144 | 24 | | var notification = new Notification( |
| 144 | 25 | | @class.InstitutionId, |
| 144 | 26 | | "Nova atividade", |
| 144 | 27 | | $"{@class.Discipline.Name}: {activity.Title}", |
| 144 | 28 | | UsersGroup.Students, |
| 144 | 29 | | false |
| 144 | 30 | | ); |
| 144 | 31 | | ctx.Add(notification); |
| | 32 | |
|
| | 33 | | // var batch = CommandBatch.New(@class.InstitutionId, CommandBatchType.SendNewClassActivityEmailCommandsBatch, s |
| | 34 | | // ctx.Add(batch); |
| 428 | 35 | | foreach (var student in students) |
| | 36 | | { |
| 70 | 37 | | ctx.Add(new UserNotification(student.Id, notification.Id)); |
| | 38 | | // ctx.AddCommand(@class.InstitutionId, new SendNewClassActivityEmailCommand(student.Id, notification.Id), p |
| | 39 | | } |
| | 40 | |
|
| | 41 | | // var nexCommand = ctx.AddCommand(@class.InstitutionId, new NotifyTeacherNewClassActivityEmailsSendedCommand(@c |
| | 42 | | // batch.ContinueWith(nexCommand); |
| 144 | 43 | | } |
| | 44 | | } |