Handler.cs 844 B

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