using MediatR; using ReC.Application.RecActionViews.Queries; using ReC.Domain.Constants; namespace ReC.Application.RecActionViews.Commands; public record InvokeBatchRecActionViewsCommand : IRequest { public long ProfileId { get; init; } } public static class InvokeBatchRecActionViewsCommandExtensions { public static Task InvokeBatchRecActionView(this ISender sender, long profileId, CancellationToken cancel = default) => sender.Send(new InvokeBatchRecActionViewsCommand { ProfileId = profileId }, cancel); } public class InvokeRecActionViewsCommandHandler(ISender sender) : IRequestHandler { public async Task Handle(InvokeBatchRecActionViewsCommand request, CancellationToken cancel) { var actions = await sender.Send(new ReadRecActionViewQuery() { ProfileId = request.ProfileId, Invoked = false }, cancel); foreach (var action in actions) { var ok = await sender.Send(action.ToInvokeCommand(), cancel); if (!ok) switch (action.ErrorAction) { case ErrorAction.Continue: break; default: return; } } } }