Exemplo n.º 1
0
            //模型级错误的验证方式。
            //只有不存在属性级错误的时候会调用;如果有属性级错误不会调用
            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) }));
                }
            }
Exemplo n.º 2
0
            //模型级错误的验证方式。
            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) }));
                }
            }
Exemplo n.º 3
0
        public IActionResult Create(HolidayVo vo)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index", vo));
            }
            var record = new T_Holiday
            {
                Holiday      = DateAttribute.FromDateString(vo.Day).Value,
                Holiday_Name = vo.Name
            };

            record.Insert();
            return(View(record));
        }
Exemplo n.º 4
0
        public IActionResult Update(HolidayVo vo)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", vo));
            }
            var record = new T_Holiday
            {
                Id           = vo.Id,
                Holiday      = DateAttribute.FromDateString(vo.Day).Value,
                Holiday_Name = vo.Name
            };

            record.Update();
            return(View(vo));
        }