Handler.cs 1019 B

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