Example #1
0
        public ComposedConditionNodeValidator()
        {
            this.integerConditionNodeValidator = new ValueConditionNodeValidator <int, TConditionType>();
            this.decimalConditionNodeValidator = new ValueConditionNodeValidator <decimal, TConditionType>();
            this.stringConditionNodeValidator  = new ValueConditionNodeValidator <string, TConditionType>();
            this.booleanConditionNodeValidator = new ValueConditionNodeValidator <bool, TConditionType>();

            this.RuleFor(c => c.LogicalOperator).IsContainedOn(LogicalOperators.And, LogicalOperators.Or);
            this.RuleForEach(c => c.ChildConditionNodes).Custom((cn, cc) => cn.PerformValidation(new ConditionNodeValidationArgs <TConditionType>
            {
                BooleanConditionNodeValidator  = this.booleanConditionNodeValidator,
                ComposedConditionNodeValidator = this,
                CustomContext = cc,
                DecimalConditionNodeValidator = this.decimalConditionNodeValidator,
                IntegerConditionNodeValidator = this.integerConditionNodeValidator,
                StringConditionNodeValidator  = this.stringConditionNodeValidator
            }));
        }
        public RuleValidator()
        {
            this.composedConditionNodeValidator = new ComposedConditionNodeValidator <TConditionType>();
            this.integerConditionNodeValidator  = new ValueConditionNodeValidator <int, TConditionType>();
            this.decimalConditionNodeValidator  = new ValueConditionNodeValidator <decimal, TConditionType>();
            this.stringConditionNodeValidator   = new ValueConditionNodeValidator <string, TConditionType>();
            this.booleanConditionNodeValidator  = new ValueConditionNodeValidator <bool, TConditionType>();

            this.RuleFor(r => r.ContentContainer).NotNull();
            this.RuleFor(r => r.DateBegin).NotEmpty();
            this.RuleFor(r => r.DateEnd).GreaterThanOrEqualTo(r => r.DateBegin).When(r => r.DateEnd != null);
            this.RuleFor(r => r.Name).NotNull().NotEmpty();
            this.RuleFor(r => r.RootCondition).Custom((cn, cc) => cn.PerformValidation(new ConditionNodeValidationArgs <TConditionType>
            {
                BooleanConditionNodeValidator  = this.booleanConditionNodeValidator,
                ComposedConditionNodeValidator = this.composedConditionNodeValidator,
                CustomContext = cc,
                DecimalConditionNodeValidator = this.decimalConditionNodeValidator,
                IntegerConditionNodeValidator = this.integerConditionNodeValidator,
                StringConditionNodeValidator  = this.stringConditionNodeValidator
            }));
        }