diff --git a/src/ReC.Application/Common/Validations/InvokeBatchRecActionViewsCommandValidator.cs b/src/ReC.Application/Common/Validations/InvokeBatchRecActionViewsCommandValidator.cs new file mode 100644 index 0000000..53783c1 --- /dev/null +++ b/src/ReC.Application/Common/Validations/InvokeBatchRecActionViewsCommandValidator.cs @@ -0,0 +1,22 @@ +using FluentValidation; +using MediatR; +using ReC.Application.RecActions.Commands; +using ReC.Application.Results.Queries; + +namespace ReC.Application.Common.Validations; + +public class InvokeBatchRecActionViewsCommandValidator : AbstractValidator +{ + public InvokeBatchRecActionViewsCommandValidator(ISender sender) + { + RuleFor(x => x.References.BatchId) + .NotEmpty() + .WithMessage("BatchId is required.") + .MustAsync(async (batchId, cancel) => + { + var any = await sender.Send(new AnyResultViewQuery(BatchId: batchId), cancel); + return !any; + }) + .WithMessage(x => $"Cannot invoke rec actions for batch '{x.References.BatchId}' because there are already results associated with it."); + } +}