Example #1
0
        /// <summary>
        ///异步验证
        /// </summary>
        public static async Task DoValidationAsync(IUsersRespository usersRespository, Users users, string validatorType)
        {
            var usersValidator    = new UsersValidator(usersRespository);
            var validatorReresult = await usersValidator.DoValidateAsync(users, validatorType);

            if (!validatorReresult.IsValid)
            {
                throw new DomainException(validatorReresult);
            }
        }
Example #2
0
        /// <summary>
        ///异步验证
        /// </summary>
        public static async Task DoValidationAsync(IUsersRespository usersRespository, IEnumerable <Users> userss, string validatorType)
        {
            var usersValidator  = new UsersValidator(usersRespository);
            var domainException = new DomainException();

            foreach (var users in userss)
            {
                var validatorReresult = await usersValidator.DoValidateAsync(users, validatorType);

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

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