| | 1 | | using Syki.Back.Features.Academic.CreateNotification; |
| | 2 | |
|
| | 3 | | namespace Syki.Back.Features.Student.CreateClassActivityWork; |
| | 4 | |
|
| | 5 | | [CommandDescription("Criar notificação de nota adicionada")] |
| | 6 | | public record CreateNewStudentClassNoteNotificationCommand(Guid ClassActivityId, Guid UserId) : ICommand; |
| | 7 | |
|
| 44 | 8 | | public class CreateNewStudentClassNoteNotificationCommandHandler(SykiDbContext ctx) : ICommandHandler<CreateNewStudentCl |
| | 9 | | { |
| | 10 | | public async Task Handle(CommandId commandId, CreateNewStudentClassNoteNotificationCommand command) |
| | 11 | | { |
| 44 | 12 | | var activity = await ctx.ClassActivities |
| 44 | 13 | | .Where(x => x.Id == command.ClassActivityId) |
| 44 | 14 | | .Select(x => new { x.ClassId, x.Title }) |
| 44 | 15 | | .FirstAsync(); |
| | 16 | |
|
| 44 | 17 | | var institutionId = await ctx.Classes |
| 44 | 18 | | .Where(x => x.Id == activity.ClassId) |
| 44 | 19 | | .Select(x => x.InstitutionId) |
| 44 | 20 | | .FirstAsync(); |
| | 21 | |
|
| 44 | 22 | | var notification = new Notification( |
| 44 | 23 | | institutionId, |
| 44 | 24 | | "Nota adicionada", |
| 44 | 25 | | $"Confira sua nota na atividade: {activity.Title}", |
| 44 | 26 | | UsersGroup.Students, |
| 44 | 27 | | false |
| 44 | 28 | | ); |
| | 29 | |
|
| 44 | 30 | | ctx.AddRange(notification, new UserNotification(command.UserId, notification.Id)); |
| 44 | 31 | | } |
| | 32 | | } |