Database Reference
In-Depth Information
The add method makes the status the CURRENTPOST but also determines whether a previous CURRENTPOST exists
and, if one does, changes its relationship type to NEXTPOST . In addition, the tags connected to the status update will be
merged into the graph and connected to the status update via the HAS relationship type.
Listing 7-33. The add Method in ContentService
public MappedContent add(Content content, string username)
{
content.contentId = Guid.NewGuid().ToString();
content.timestamp = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
content.tagstr = removeTrailingComma(content.tagstr);
// splits up the comma separated string into arrays and removes any empties.
// each tag uses MERGE and connected to the the content node thru the HAS,
e.g content-[:HAS]->tag
// remember that MERGE will create if it doesn't exist otherwise based on the
properties provided
String[] tags = content.tagstr.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
MappedContent contentItem = _graphClient.Cypher
.Match(" (user { username: {u}}) ")
.WithParam("u", username)
.CreateUnique(" (user)-[:CURRENTPOST]->(newLP:Content { title:{title}, url:{url}, " +
" tagstr:{tagstr}, timestamp:{timestamp}, contentId:{contentId} }) ")
.WithParams(new { title = content.title, url = content.url,
tagstr = content.tagstr, timestamp=content.timestamp, contentId=content.contentId})
.With("user, newLP")
.ForEach(" (tagName in {tags} | " +
"MERGE (t:Tag {wordPhrase:tagName})" +
" MERGE (newLP)-[:HAS]->(t) " +
" )")
.WithParam("tags",tags)
.With("user, newLP")
.OptionalMatch(" (newLP)<-[:CURRENTPOST]-(user)-[oldRel:CURRENTPOST]->(oldLP)")
.Delete(" oldRel ")
.Create(" (newLP)-[:NEXTPOST]->(oldLP) ")
.With("user, newLP")
.Return(() => Return.As<MappedContent>(" { contentId: newLP.contentId, title: newLP.title,
url: newLP.url," +
" tagstr: newLP.tagstr, timestamp: newLP.timestamp, userNameForPost: {u}, owner: true } "))
.Results.Single();
return contentItem;
}
Editing a Status Update
When status updates are displayed, the current user's status updates will contain a link to “Edit” the status. Once
clicked, it will open the form, similar to the “Add Content” link, but it will populate the form with the status update
values and modify the form button to read “Edit Content”, as shown in Figure 7-7 . Notice that clicking “Cancel” under
the heading removes the values and returns the form to its ready state.
 
Search WWH ::




Custom Search