Esempio n. 1
0
            public RulesBundle(ContextModel context, MainRule rule)
            {
                CustomerDivisionAuthorization =
                    new ResourceAuthorizationRule <
                        Olma.CustomerDivision,
                        CanCreateVoucherRequirement,
                        DivisionPermissionResource>(context.CustomerDivisionId, parentRule: rule)
                    .Include(i => i.PostingAccount);

                IssuerDivisionHasPostingAccount = new ValidOperatorRule <ContextModel>(
                    (ctx) => ctx.Type == VoucherType.Direct,
                    context,
                    ctx => ctx.CustomerDivision.PostingAccount != null,
                    new PostingAccountRequired(),
                    parentRule: rule,
                    nameof(IssuerDivisionHasPostingAccount));

                RecipientHasDefaultPostingAccount = new ValidOperatorRule <ContextModel>(
                    (ctx) => ctx.Type == VoucherType.Direct,
                    context,
                    ctx =>
                {
                    var repository = rule.ServiceProvider.GetService <IRepository <Olma.CustomerPartner> >();

                    var customerPartner = repository.FindByCondition(cp =>
                                                                     cp.RowGuid == ctx.Parent.RecipientGuid &&
                                                                     !cp.IsDeleted)
                                          .IgnoreQueryFilters()
                                          .Include(cp => cp.Partner).ThenInclude(p => p.DefaultPostingAccount)
                                          .FirstOrDefault();

                    return(customerPartner?.Partner?.DefaultPostingAccount != null);
                },
                    new RecipientHasDefaultPostingAccount(),
                    parentRule: rule,
                    nameof(RecipientHasDefaultPostingAccount));

                PrintCountValid = new ValidOperatorRule <ContextModel>(
                    context,
                    ctx => ctx.PrintCount > 0,
                    new NotAllowedByRule(),
                    parentRule: rule,
                    nameof(PrintCountValid));

                DocumentType = new DocumentTypeRule(context, parentRule: rule);

                Voucher = new VoucherRule(context, parentRule: rule);

                LocalizationLanguageValid = new LocalizationLanguageValidRule(context.PrintLanguageId, parentRule: rule);

                BlacklistTerms = new BlacklistTermsRule(context, parentRule: rule);
            }
            public RulesBundle(ContextModel context, BlacklistTermsRule termsRule)
            {
                BlacklistLicensePlate = new ValidOperatorRule <ContextModel>(
                    context,
                    termsRule.ValidLicensePlate,
                    new BlacklistMatch(),
                    parentRule: termsRule,
                    nameof(BlacklistLicensePlate));

                BlacklistOther = new ValidOperatorRule <ContextModel>(
                    context,
                    termsRule.ValidOther,
                    new BlacklistMatch(),
                    parentRule: termsRule,
                    nameof(BlacklistOther));
            }
 public ContextModel(MainRule.ContextModel parent, BlacklistTermsRule termsRule) : base(parent, termsRule)
 {
     Rules = new RulesBundle(this, termsRule);
 }