Handler.cs 949 B

12345678910111213141516171819202122232425262728
  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. public sealed class Handler(IAppDbContext db, IEditorImageService editorImage, ICacheService cache) : 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. await cache.RemoveByPrefixAsync("document:", ct);
  22. }
  23. }