Handler.cs 892 B

123456789101112131415161718192021222324252627
  1. using Application.Abstractions.Messaging;
  2. using Application.Abstractions.Data;
  3. using SharedKernel.Storage;
  4. using Microsoft.EntityFrameworkCore;
  5. namespace Application.Features.Document.Delete
  6. {
  7. public sealed class Handler(IAppDbContext db, IEditorImageService editorImage) : ICommandHandler<Command>
  8. {
  9. public async Task Handle(Command request, CancellationToken ct)
  10. {
  11. if (request.IDs is null || request.IDs.Length == 0)
  12. {
  13. return;
  14. }
  15. var contents = await db.Document.Where(c => request.IDs.Contains(c.ID)).Select(c => c.Content).ToListAsync(ct);
  16. foreach (var content in contents)
  17. {
  18. await editorImage.CleanupByContentAsync(content, ct);
  19. }
  20. await db.Document.Where(c => request.IDs.Contains(c.ID)).ExecuteDeleteAsync(ct);
  21. }
  22. }
  23. }