Database Reference
In-Depth Information
Listing 7-41. The createUserViewAndReturnViews Method in ProductService
// capture view and return all views
public List<MappedProductUserViews> createUserViewAndReturnViews(string username, long
productNodeId)
{
DateTime datetime = DateTime.UtcNow;
string timestampAsStr = datetime.ToString("MM/dd/yyyy") + " at " +
datetime.ToString("h:mm tt");
long timestampAsLong = (long)(datetime.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
List<MappedProductUserViews> mappedProductUserViews = _graphClient.Cypher
.Match(" (p:Product), (u:User { username:{u} }) ")
.WithParam("u",username)
.Where("id(p) = {productNodeId}")
.WithParam("productNodeId",productNodeId)
.With(" u,p")
.Merge(" (u)-[r:VIEWED]->(p)")
.Set(" r.dateAsStr={d}, r.timestamp={t} ")
.WithParams(new { d = timestampAsStr, t = timestampAsLong })
.With(" u ")
.Match(" (u)-[r:VIEWED]->(p) ")
.Return(() => Return.As<MappedProductUserViews>("{ title: p.title, "+
"dateAsStr: r.dateAsStr }"))
.OrderByDescending("r.timestamp")
.Results.ToList();
return mappedProductUserViews;
}
Filtering Consumption for Users
One practical use of the consumption model would be to create a content trail for users, as shown in
Figure 7-10 . As a user clicks on items in the scrolling product stream, the interaction is captured using
createUserViewAndReturnViews , which ultimately returns a List of relationship objects of the VIEWED type, which are
displayed using the ViewModel object called MappedProductUserViews .
 
Search WWH ::




Custom Search