Handler.cs 874 B

1234567891011121314151617181920212223242526272829303132
  1. using Application.Abstractions.Data;
  2. using Application.Abstractions.Messaging;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace Application.Features.Forum.CommentReport.UpdateStatus;
  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 reports = await db.CommentReport
  14. .Where(c => request.IDs.Contains(c.ID))
  15. .ToListAsync(ct);
  16. foreach (var report in reports)
  17. {
  18. report.Status = request.Status;
  19. if (request.Memo is not null)
  20. {
  21. report.Memo = request.Memo;
  22. }
  23. report.UpdatedAt = DateTime.UtcNow;
  24. }
  25. await db.SaveChangesAsync(ct);
  26. }
  27. }