コード例 #1
0
        /// <summary>
        ///异步验证
        /// </summary>
        public static async Task DoValidationAsync(IRoleElementRespository roleElementRespository, RoleElement roleElement, string validatorType)
        {
            var roleElementValidator = new RoleElementValidator(roleElementRespository);
            var validatorReresult    = await roleElementValidator.DoValidateAsync(roleElement, validatorType);

            if (!validatorReresult.IsValid)
            {
                throw new DomainException(validatorReresult);
            }
        }
コード例 #2
0
        /// <summary>
        ///异步验证
        /// </summary>
        public static async Task DoValidationAsync(IRoleElementRespository roleElementRespository, IEnumerable <RoleElement> roleElements, string validatorType)
        {
            var roleElementValidator = new RoleElementValidator(roleElementRespository);
            var domainException      = new DomainException();

            foreach (var roleElement in roleElements)
            {
                var validatorReresult = await roleElementValidator.DoValidateAsync(roleElement, validatorType);

                if (!validatorReresult.IsValid)
                {
                    domainException.AddErrors(validatorReresult);
                }
            }

            if (domainException.ValidationErrors.ErrorItems.Any())
            {
                throw domainException;
            }
        }