Exemple #1
0
        protected override void Validate(Entity entity, RuleArgs e)
        {
            var value = Convert.ToDouble(entity.GetProperty(e.Property));

            var min = this.Min;
            if (value < min)
            {
                if (this.MessageBuilder != null)
                {
                    e.BrokenDescription = this.MessageBuilder(entity);
                }
                else
                {
                    e.BrokenDescription = string.Format("{0} 不能低于 {1}。".Translate(), e.DisplayProperty(), min);
                }
            }
            else
            {
                var max = this.Max;
                if (value > max)
                {
                    if (this.MessageBuilder != null)
                    {
                        e.BrokenDescription = this.MessageBuilder(entity);
                    }
                    else
                    {
                        e.BrokenDescription = string.Format("{0} 不能超过 {1}。".Translate(), e.DisplayProperty(), max);
                    }
                }
            }
        }
Exemple #2
0
        protected override void Validate(Entity entity, RuleArgs e)
        {
            var value = Convert.ToDouble(entity.GetProperty(e.Property));

            if (value <= 0)
            {
                if (this.MessageBuilder != null)
                {
                    e.BrokenDescription = this.MessageBuilder(entity);
                }
                else
                {
                    e.BrokenDescription = string.Format("{0} 需要是正数。".Translate(), e.DisplayProperty());
                }
            }
        }
Exemple #3
0
        protected override void Validate(Entity entity, RuleArgs e)
        {
            var value = (string)entity.GetProperty(e.Property) ?? string.Empty;

            if (!string.IsNullOrEmpty(value))
            {
                if (!this.Regex.IsMatch(value))
                {
                    if (this.MessageBuilder != null)
                    {
                        e.BrokenDescription = this.MessageBuilder(entity);
                    }
                    else
                    {
                        e.BrokenDescription = string.Format(
                            "{0} 必须是 {1}。".Translate(),
                            e.DisplayProperty(),
                            this.RegexLabel.Translate()
                            );
                    }
                }
            }
        }
Exemple #4
0
        protected override void Validate(Entity entity, RuleArgs e)
        {
            var property = e.Property;

            bool isNull = false;

            if (property is IRefProperty)
            {
                var id = entity.GetRefNullableId((property as IRefProperty).RefIdProperty);
                isNull = id == null;
            }
            else
            {
                var value = entity.GetProperty(property);
                if (property.PropertyType == typeof(string))
                {
                    isNull = string.IsNullOrEmpty(value as string);
                }
                else
                {
                    isNull = value == null;
                }
            }

            if (isNull)
            {
                if (this.MessageBuilder != null)
                {
                    e.BrokenDescription = this.MessageBuilder(entity);
                }
                else
                {
                    e.BrokenDescription = string.Format("{0} 里没有输入值。".Translate(), e.DisplayProperty());
                }
            }
        }
 protected override void Validate(Entity entity, RuleArgs e)
 {
     var value = entity.GetProperty(e.Property) as string;
     if (!string.IsNullOrEmpty(value))
     {
         var min = this.Min;
         if (value.Length < min)
         {
             if (this.MessageBuilder != null)
             {
                 e.BrokenDescription = this.MessageBuilder(entity);
             }
             else
             {
                 e.BrokenDescription = string.Format(
                     "{0} 不能低于 {1} 个字符。".Translate(),
                     e.DisplayProperty(), min
                     );
             }
         }
         else
         {
             var max = this.Max;
             if (value.Length > max)
             {
                 if (this.MessageBuilder != null)
                 {
                     e.BrokenDescription = this.MessageBuilder(entity);
                 }
                 else
                 {
                     e.BrokenDescription = string.Format(
                         "{0} 不能超过 {1} 个字符。".Translate(),
                         e.DisplayProperty(), max
                         );
                 }
             }
         }
     }
 }