public static IRuleBuilderOptions <T, Guid?> ClientMustBeInScope <T>(this IRuleBuilder <T, Guid?> ruleBuilder, DataContext dataContext, ScopeOptions scope) { return(ruleBuilder.MustAsync(async(root, clientId, context) => { if (!clientId.HasValue) { return false; } return await ScopeQuery.IsClientInOrganisation(dataContext, scope, clientId.Value); }) .WithMessage((root, clientId) => { if (!clientId.HasValue) { return NOT_EMPTY_MESSAGE; } return DOESNT_EXIST_MESSAGE; }) .WithName("Client")); }