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; } }
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); }
public bool IsValid(CommandEnum.Type cmdType) { ValidationResult = new UserValidator(cmdType).Validate(this); return(ValidationResult.IsValid); }