public static IRuleBuilderOptions <T, Guid?> CommissionSplitRuleMustBeInScope <T>(this IRuleBuilder <T, Guid?> ruleBuilder, DataContext dataContext, ScopeOptions scope) { return(ruleBuilder.MustAsync(async(root, commissionSplitRuleId, context) => { if (!commissionSplitRuleId.HasValue) { return false; } var rule = await dataContext.CommissionSplitRule.FindAsync(commissionSplitRuleId); if (rule == null) { return false; } return await ScopeQuery.IsUserInScope(dataContext, scope, rule.UserId); }) .WithMessage((root, commissionSplitRuleId) => { if (!commissionSplitRuleId.HasValue) { return NOT_EMPTY_MESSAGE; } return DOESNT_EXIST_MESSAGE; }) .WithName("Commission Split Rule")); }
public static IRuleBuilderOptions <T, Guid?> PolicyMustBeInScope <T>(this IRuleBuilder <T, Guid?> ruleBuilder, DataContext dataContext, ScopeOptions scope) { return(ruleBuilder.MustAsync(async(root, policyId, context) => { if (!policyId.HasValue) { return false; } var policy = await dataContext.Policy.FindAsync(policyId); if (policy == null) { return false; } return await ScopeQuery.IsUserInScope(dataContext, scope, policy.UserId); }) .WithMessage((root, id) => { if (!id.HasValue) { return NOT_EMPTY_MESSAGE; } return DOESNT_EXIST_MESSAGE; }) .WithName("Policy")); }
public static IRuleBuilderOptions <T, Guid> UserMustBeInScope <T>(this IRuleBuilder <T, Guid> ruleBuilder, DataContext dataContext, ScopeOptions scope) { return(ruleBuilder.MustAsync(async(root, userId, context) => { return await ScopeQuery.IsUserInScope(dataContext, scope, userId); }) .WithMessage(DOESNT_EXIST_MESSAGE) .WithName("User")); }