Last active
September 9, 2016 17:40
-
-
Save JogoShugh/eda0f2bc54ae42000f68f5ee6e9f4149 to your computer and use it in GitHub Desktop.
Praveen Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var client = new VersionOneRestClient(V1_REST_API_URL, USERNAME, PASSWORD); | |
var results = client.Query("Story") | |
.Select("Name", "Status.Name", "AssetState", "IsDeleted") | |
.Where( | |
Or( | |
Equal("Name", "Story 1"), | |
NotEqual("AssetState", 64) | |
) | |
) | |
.Retrieve(); | |
foreach (dynamic story in results) | |
{ | |
// Debug.WriteLine($"Story OID Token: {story.OidToken}"); // TODO: fix this part | |
Debug.WriteLine($"Name: {story.Name}"); | |
Debug.WriteLine($"Status: {story["Status.Name"]}"); | |
Debug.WriteLine($"AssetState: {story.AssetState}"); | |
} | |
/** Alternative syntax ideas: | |
// Using chained Or after an operator: | |
var results = client.Query("Story") | |
.Select("Name", "Status.Name", "AssetState", "IsDeleted") | |
.Where( | |
Equal("Name", "Story 1").Or(NotEqual("AssetState", 64)) | |
) | |
.Retrieve(); | |
// Using extension methods: | |
var results = client.Query("Story") | |
.Select("Name", "Status.Name", "AssetState", "IsDeleted") | |
.Where( | |
"Name".Equal("Story 1") | |
.Or( | |
"AssetState".Equal(64) | |
) | |
) | |
.Retrieve(); | |
**/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
V1Connector connector = V1Connector | |
.WithInstanceUrl("http://localhost/VersionOne.Web") | |
.WithUserAgentHeader("AppName", "1.0") | |
.WithUsernameAndPassword("admin", "admin") | |
.Build(); | |
IServices services = new Services(connector); | |
IAssetType storyType = services.Meta.GetAssetType("Story"); | |
IAttributeDefinition nameAttribute = storyType.GetAttributeDefinition("Name"); | |
IAttributeDefinition statusAttribute = storyType.GetAttributeDefinition("Status"); | |
IAttributeDefinition asseteStateAttribute = storyType.GetAttributeDefinition("AssetState"); | |
IAttributeDefinition isDeletedAttribute = storyType.GetAttributeDefinition("IsDeleted"); | |
Query query = new Query(storyType); | |
query.Selection.Add(nameAttribute); | |
query.Selection.Add(statusAttribute); | |
query.Selection.Add(asseteStateAttribute); | |
FilterTerm isDeletedFilterTerm = new FilterTerm(isDeletedAttribute); | |
isDeletedFilterTerm.Equal("true"); | |
FilterTerm isClosedFilterTerm = new FilterTerm(asseteStateAttribute); | |
isClosedFilterTerm.Equal("Closed"); | |
OrFilterTerm isDeletedOrIsClosedFilterTerm = new OrFilterTerm(isDeletedFilterTerm, isClosedFilterTerm); | |
query.Filter = isDeletedOrIsClosedFilterTerm; | |
QueryResult result = services.Retrieve(query); | |
foreach (Asset story in result.Assets) | |
{ | |
Debug.WriteLine(story.Oid.Token); | |
Debug.WriteLine(story.GetAttribute(nameAttribute).Value); | |
Debug.WriteLine(story.GetAttribute(statusAttribute).Value); | |
Debug.WriteLine(story.GetAttribute(asseteStateAttribute).Value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment