Example #1
0
            public RulesBundle(ContextModel context, MainRule rule)
            {
                UpnValid = new ValidOperatorRule <ContextModel>(
                    context,
                    ctx =>
                {
                    var serviceProvider = rule.ServiceProvider;
                    var dbContext       = serviceProvider.GetService <OlmaDbContext>();
                    var query           = dbContext.Users
                                          .Where(u => u.Upn == ctx.Upn)
                                          .IgnoreQueryFilters();

                    return(!query.Any());
                },
                    parentRule: rule,
                    ruleName: nameof(UpnValid),
                    message: new NotAllowedByRule());

                UserUpnRequired = new ValidOperatorRule <ContextModel>(
                    context,
                    ctx => !string.IsNullOrEmpty(ctx.Upn),
                    parentRule: rule,
                    ruleName: nameof(UserUpnRequired),
                    message: new NotAllowedByRule());

                ValidEmail = new ValidEmailRule <ContextModel>(context, ctx => ctx.Parent.Email);

                Password = new RandomPasswordRule();
            }