public async Task <Unit> Handle(CleanupAttachmentsCommand request, CancellationToken cancellationToken) { foreach (var file in Directory.EnumerateFiles(fileStorageSettings.BasePath)) { var id = Guid.Parse(Path.GetFileNameWithoutExtension(file).Split("_")[0]); if (null == await fileDb.ByIdAsync(id)) { File.Delete(file); } } return(Unit.Value); }
public async Task <Unit> Handle(DeleteAttachmentCommand request, CancellationToken cancellationToken) { var attachment = await fileDb.ByIdAsync(request.Id); if (null == attachment) { throw new AttachmentNotFoundException(request.Id); } foreach (var subAttachment in attachment.SubAttachments) { await DeleteFile(subAttachment.RealFilename()); } await DeleteFile(attachment.RealFilename()); await fileDb.DeleteAsync(request.Id, cancellationToken); await fileDb.CommitAsync(cancellationToken); return(Unit.Value); }