Handler.cs 784 B

12345678910111213141516171819202122232425262728
  1. using Application.Abstractions.Data;
  2. using Application.Abstractions.Messaging;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace Application.Features.Forum.CommentFile.ToggleDisable;
  5. public sealed class Handler(IAppDbContext db) : ICommandHandler<Command>
  6. {
  7. public async Task Handle(Command request, CancellationToken ct)
  8. {
  9. if (request.IDs is null || request.IDs.Length == 0)
  10. {
  11. return;
  12. }
  13. var files = await db.CommentFile
  14. .Where(c => request.IDs.Contains(c.ID))
  15. .ToListAsync(ct);
  16. foreach (var file in files)
  17. {
  18. file.IsDisabled = request.IsDisabled;
  19. file.DisabledAt = request.IsDisabled ? DateTime.UtcNow : null;
  20. }
  21. await db.SaveChangesAsync(ct);
  22. }
  23. }