using MediatR; using ReC.Application.RecActions.Queries; namespace ReC.Application.RecActions.Commands; public record InvokeBatchRecActionsCommand : ReadRecActionQueryBase, IRequest; public static class InvokeBatchRecActionsCommandExtensions { public static Task InvokeBatchRecAction(this ISender sender, long profileId, CancellationToken cancel = default) => sender.Send(new InvokeBatchRecActionsCommand { ProfileId = profileId }, cancel); } public class InvokeRecActionsCommandHandler(ISender sender) : IRequestHandler { public async Task Handle(InvokeBatchRecActionsCommand request, CancellationToken cancel) { var actions = await sender.Send(request.ToReadQuery(q => q.Invoked = false), cancel); foreach (var action in actions) { var ok = await sender.Send(action.ToInvokeCommand(), cancel); if (!ok) switch (action.ErrorAction?.ToLowerInvariant()) { case "continue": break; default: return; } } } }