Exemplo n.º 1
0
        /// <summary>
        ///异步验证
        /// </summary>
        public static async Task DoValidationAsync(IRoleRespository roleRespository, Role role, string validatorType)
        {
            var roleValidator     = new RoleValidator(roleRespository);
            var validatorReresult = await roleValidator.DoValidateAsync(role, validatorType);

            if (!validatorReresult.IsValid)
            {
                throw new DomainException(validatorReresult);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///异步验证
        /// </summary>
        public static async Task DoValidationAsync(IRoleRespository roleRespository, IEnumerable <Role> roles, string validatorType)
        {
            var roleValidator   = new RoleValidator(roleRespository);
            var domainException = new DomainException();

            foreach (var role in roles)
            {
                var validatorReresult = await roleValidator.DoValidateAsync(role, validatorType);

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

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