예제 #1
0
        /// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
        /// <param name="isNew">是否插入</param>
        public override void Valid(Boolean isNew)
        {
            // 如果没有脏数据,则不需要进行任何处理
            if (!HasDirty)
            {
                return;
            }

            // 这里验证参数范围,建议抛出参数异常,指定参数名,前端用户界面可以捕获参数异常并聚焦到对应的参数输入框
            if (DeviceCode.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(DeviceCode), "DeviceCode不能为空!");
            }
            if (UserCode.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(UserCode), "UserCode不能为空!");
            }
            if (SubjectId.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(SubjectId), "SubjectId不能为空!");
            }
            if (ClientId.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(ClientId), "ClientId不能为空!");
            }
            if (CreationTime.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(CreationTime), "CreationTime不能为空!");
            }
            if (Expiration.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Expiration), "Expiration不能为空!");
            }
            if (Data.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Data), "Data不能为空!");
            }

            // 在新插入数据或者修改了指定字段时进行修正

            // 检查唯一索引
            // CheckExist(isNew, __.DeviceCode);
            // CheckExist(isNew, __.UserCode);
        }