示例#1
0
        public UserValidator(CommandEnum.Type cmdEnumType)
        {
            switch (cmdEnumType)
            {
            case CommandEnum.Type.CREATE:
                AddRule(new ValidationRule <UserEntity>(new CreateUserSpec(), "Teste 1"));
                break;

            case CommandEnum.Type.UPDATE:
                AddRule(new ValidationRule <UserEntity>(new UpdateUserSpec(), "Teste 2"));
                break;

            case CommandEnum.Type.DELETE:
                AddRule(new ValidationRule <UserEntity>(new RemoveUserSpec(), "Teste 3"));
                break;
            }
        }
示例#2
0
        private ValidationResult Validate(TEntity obj, CommandEnum.Type cmdType)
        {
            if (!ValidationResult.IsValid)
            {
                return(ValidationResult);
            }

            if (obj is IValidable)
            {
                var validable = obj as IValidable;

                if (!validable.IsValid(cmdType))
                {
                    ValidationResult = validable.ValidationResult;
                }
            }

            return(ValidationResult);
        }
示例#3
0
 public bool IsValid(CommandEnum.Type cmdType)
 {
     ValidationResult = new UserValidator(cmdType).Validate(this);
     return(ValidationResult.IsValid);
 }