//模型级错误的验证方式。
            //只有不存在属性级错误的时候会调用;如果有属性级错误不会调用
            public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
            {
                var holiday = DateAttribute.FromDateString(this.Day).Value;

                if (T_Holiday.Count(Where.Eq(nameof(T_Holiday.Holiday), holiday)) > 0)
                {
                    yield return(new ValidationResult("该日期已存在。不可加入重复的假期。", new string[] { nameof(Day) }));
                }
            }
            //模型级错误的验证方式。
            public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
            {
                //逻辑与新规时不太相同
                var holiday = DateAttribute.FromDateString(this.Day).Value;
                var count   = T_Holiday.Count(Where.And(
                                                  Where.Eq(nameof(T_Holiday.Holiday), holiday),
                                                  Where.NotEq(nameof(T_Holiday.Id), this.Id)
                                                  ));

                if (count > 0)
                {
                    yield return(new ValidationResult("该日期已存在。不可加入重复的假期。", new string[] { nameof(Day) }));
                }
            }
Esempio n. 3
0
 protected override int QueryRecordsCount()
 {
     return(T_Holiday.Count());
 }