Skip to content

Instantly share code, notes, and snippets.

@JogoShugh
Last active September 28, 2016 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JogoShugh/8733e07d0f565e332f676184187d7185 to your computer and use it in GitHub Desktop.
Save JogoShugh/8733e07d0f565e332f676184187d7185 to your computer and use it in GitHub Desktop.
CreateStoryWithConversation
public void CreateStoryWithConversation()
{
var v1 = V1Connector
.WithInstanceUrl(BaseUrl)
.WithUserAgentHeader("Sample", "0.0.0")
.WithUsernameAndPassword(UserName, Password);
var scope = "Scope:86271";
var name = $"Test Story {scope} Create story with conversation and mention";
var newStory = v1.Create("Story", new {
Scope = scope,
Name = name
});
var newConversation = v1.Create("Conversation");
var questionExpression = v1.Create("Expression", new {
Author = "Member:20",
AuthoredAt = DateTime.Now,
Content = "Is this a test conversation?",
BelongsTo = newConversation.OidToken,
Mentions = Relation(newStory.OidToken)
});
var answerExpression = v1.Create("Expression", new {
Author = "Member:20",
AuthoredAt = DateTime.Now.AddMinutes(15),
Content = "Yes it is!",
InReplyTo = questionExpression.OidToken
});
WriteLine($"Story OID Token: {newStory.OidToken}");
}
public void CreateStoryWithConversation()
{
var v1 = V1Connector
.WithInstanceUrl(BaseUrl)
.WithUserAgentHeader("Sample", "0.0.0")
.WithUsernameAndPassword(UserName, Password)
.Build();
var services = new Services(v1);
var contextId = IntegrationTestsHelper.GetTestProjectOid(_useOAuthEndpoints);
var storyType = services.Meta.GetAssetType("Story");
var newStory = services.New(storyType, contextId);
var nameAttribute = storyType.GetAttributeDefinition("Name");
var name = string.Format("Test Story {0} Create story with conversation", contextId);
newStory.SetAttributeValue(nameAttribute, name);
services.Save(newStory);
var conversationType = services.Meta.GetAssetType("Conversation");
var expressionType = services.Meta.GetAssetType("Expression");
var authorAttribute = expressionType.GetAttributeDefinition("Author");
var authoredAtAttribute = expressionType.GetAttributeDefinition("AuthoredAt");
var contentAttribute = expressionType.GetAttributeDefinition("Content");
var belongsToAttribute = expressionType.GetAttributeDefinition("BelongsTo");
var inReplyToAttribute = expressionType.GetAttributeDefinition("InReplyTo");
var mentionsAttribute = expressionType.GetAttributeDefinition("Mentions");
var newConversation = services.New(conversationType);
var questionExpression = services.New(expressionType);
services.Save(newConversation);
questionExpression.SetAttributeValue(authorAttribute, services.GetOid("Member:20"));
questionExpression.SetAttributeValue(authoredAtAttribute, DateTime.Now);
questionExpression.SetAttributeValue(contentAttribute, "Is this a test conversation?");
questionExpression.SetAttributeValue(belongsToAttribute, newConversation.Oid);
questionExpression.AddAttributeValue(mentionsAttribute, newStory.Oid);
services.Save(questionExpression);
var answerExpression = services.New(expressionType, questionExpression.Oid);
answerExpression.SetAttributeValue(authorAttribute, services.GetOid("Member:20"));
answerExpression.SetAttributeValue(authoredAtAttribute, DateTime.Now.AddMinutes(15));
answerExpression.SetAttributeValue(contentAttribute, "Yes it is!");
answerExpression.SetAttributeValue(inReplyToAttribute, questionExpression.Oid);
services.Save(answerExpression);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment