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

            // 这里验证参数范围,建议抛出参数异常,指定参数名,前端用户界面可以捕获参数异常并聚焦到对应的参数输入框
            if (When.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(When), "When不能为空!");
            }
            if (Source.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Source), "Source不能为空!");
            }
            if (SubjectType.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(SubjectType), "SubjectType不能为空!");
            }
            if (SubjectIdentifier.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(SubjectIdentifier), "SubjectIdentifier不能为空!");
            }
            if (Subject.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Subject), "Subject不能为空!");
            }
            if (Action.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Action), "Action不能为空!");
            }
            if (ResourceType.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(ResourceType), "ResourceType不能为空!");
            }
            if (Resource.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Resource), "Resource不能为空!");
            }
            if (ResourceIdentifier.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(ResourceIdentifier), "ResourceIdentifier不能为空!");
            }
            if (NormalisedSubject.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(NormalisedSubject), "NormalisedSubject不能为空!");
            }
            if (NormalisedAction.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(NormalisedAction), "NormalisedAction不能为空!");
            }
            if (NormalisedResource.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(NormalisedResource), "NormalisedResource不能为空!");
            }
            if (NormalisedSource.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(NormalisedSource), "NormalisedSource不能为空!");
            }

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