Handler.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132
  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.Crypto.List.Delete
  7. {
  8. public sealed class Handler(IAppDbContext db, IFileStorage fileStorage, 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 logos = await db.Coin.Where(c => request.IDs.Contains(c.ID)).Select(c => c.LogoImage).ToListAsync(ct);
  17. foreach (var logo in logos)
  18. {
  19. if (logo != null)
  20. {
  21. fileStorage.DeleteByUrl(logo);
  22. }
  23. }
  24. await db.Coin.Where(c => request.IDs.Contains(c.ID)).ExecuteDeleteAsync(ct);
  25. await cache.RemoveByPrefixAsync("crypto:", ct);
  26. }
  27. }
  28. }