| 12345678910111213141516171819202122232425262728 |
- using Application.Abstractions.Data;
- using Application.Abstractions.Messaging;
- using SharedKernel.Storage;
- using Microsoft.EntityFrameworkCore;
- namespace Application.Features.Forum.CommentFile.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 files = await db.CommentFile.Where(c => request.IDs.Contains(c.ID)).ToListAsync(ct);
- foreach (var file in files)
- {
- fileStorage.DeleteByUrl(file.Url);
- }
- db.CommentFile.RemoveRange(files);
- await db.SaveChangesAsync(ct);
- }
- }
|