| 12345678910111213141516171819202122232425262728293031323334 |
- using Application.Abstractions.Messaging;
- using Application.Abstractions.Data;
- using SharedKernel.Storage;
- using Microsoft.EntityFrameworkCore;
- namespace Application.Features.Banner.Item.Delete;
- public sealed class Handler(IAppDbContext db, IFileStorage fileStorage) : ICommandHandler<Command>
- {
- public async Task Handle(Command request, CancellationToken ct)
- {
- if (request.IDs is null || request.IDs.Length == 0)
- {
- return;
- }
- var images = await db.BannerItem.Where(c => request.IDs.Contains(c.ID)).Select(c => new { c.DesktopImage, c.MobileImage }).ToListAsync(ct);
- foreach (var img in images)
- {
- if (img.DesktopImage != null)
- {
- fileStorage.DeleteByUrl(img.DesktopImage);
- }
- if (img.MobileImage != null)
- {
- fileStorage.DeleteByUrl(img.MobileImage);
- }
- }
- await db.BannerItem.Where(c => request.IDs.Contains(c.ID)).ExecuteDeleteAsync(ct);
- }
- }
|