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);
 }
예제 #3
0
            public RulesBundle(ContextModel context, MainRule rule)
            {
                CustomerDivisionAuthorizationRule = new ResourceAuthorizationRule <
                    Olma.CustomerDivision,
                    CanCreateLoadCarrierReceiptRequirement,
                    DivisionPermissionResource>(context.Request.CustomerDivisionId, rule)
                                                    .Include(customerDivision => customerDivision.PostingAccount);

                LicensePlateCountryIdRequired = new ValidOperatorRule <ContextModel>(context,
                                                                                     model => model.Request.LicensePlateCountryId > 0,
                                                                                     new NotAllowedByRule(),
                                                                                     parentRule: rule,
                                                                                     ruleName: nameof(LicensePlateCountryIdRequired));

                TruckDriverNameRequired = new ValidOperatorRule <ContextModel>(context,
                                                                               model => !string.IsNullOrEmpty(model.Request.TruckDriverName),
                                                                               new NotAllowedByRule(),
                                                                               parentRule: rule,
                                                                               ruleName: nameof(TruckDriverNameRequired));

                LicensePlateRequired = new ValidOperatorRule <ContextModel>(context,
                                                                            model => !string.IsNullOrEmpty(model.Request.LicensePlate),
                                                                            new NotAllowedByRule(),
                                                                            parentRule: rule,
                                                                            ruleName: nameof(LicensePlateRequired));

                PositionsValid = new ValidOperatorRule <ContextModel>(context,
                                                                      model =>
                                                                      model.Request.Positions.Any() &&
                                                                      model.Request.Positions.All(p => p.Quantity > 0),
                                                                      new NotAllowedByRule(),
                                                                      parentRule: rule,
                                                                      ruleName: nameof(PositionsValid));

                MoreInformationValid = new ValidOperatorRule <ContextModel>(context,
                                                                            model =>
                {
                    if (context.Request.DigitalCode != null)
                    {
                        return(true);
                    }

                    switch (context.Request.Type)
                    {
                    case LoadCarrierReceiptType.Delivery:
                        return(!string.IsNullOrEmpty(model.Request.DeliveryNoteNumber));

                    case LoadCarrierReceiptType.Pickup:
                        return(!string.IsNullOrEmpty(model.Request.PickUpNoteNumber));

                    case LoadCarrierReceiptType.Exchange:
                    default:
                        return(true);
                    }
                },
                                                                            new NotAllowedByRule(),
                                                                            parentRule: rule,
                                                                            ruleName: nameof(MoreInformationValid));

                DigitalCodePristine = new ValidOperatorRule <ContextModel>(
                    condition: ctx => !string.IsNullOrWhiteSpace(ctx.Request.DigitalCode),
                    context,
                    model =>
                {
                    var expressCodeRepository = rule.ServiceProvider.GetService <IRepository <Olma.ExpressCode> >();
                    var expressCodeExists     = expressCodeRepository.FindAll()
                                                .Any(code => code.DigitalCode == context.Request.DigitalCode);

                    if (expressCodeExists)
                    {
                        return(true);
                    }

                    var repository = rule.ServiceProvider.GetService <IRepository <Olma.LoadCarrierReceipt> >();
                    var exists     = repository
                                     .Exists(loadCarrierReceipt => loadCarrierReceipt.DigitalCode == context.Request.DigitalCode &&
                                             loadCarrierReceipt.Type == context.Request.Type &&
                                             !loadCarrierReceipt.Document.State.IsCanceled);

                    return(!exists);
                },
                    new DigitalCodeAlreadyUsed(),
                    parentRule: rule,
                    ruleName: nameof(DigitalCodePristine));

                BlacklistTerms = new BlacklistTermsRule(context, rule);
            }