Database Reference
In-Depth Information
Listing 7-51. The Purchase Object
public class Purchase
{
public long nodeId { get; set; }
public string purhcaseId { get; set; }
}
In addition, each one of the following examples makes use of the MappedProductUserPurchase ViewModel found
in Listing 7-52.
Listing 7-52. The View Model Object - MappedProductUserPurchase
public class MappedProductUserPurchase
{
public string productId { get; set; }
public string title { get; set; }
public List<string> fullname { get; set; }
public string wordPhrase { get; set; }
public int cfriends { get; set; }
}
Products Purchased by Friends
To get all of the products that have been purchase by friends, the friendsPurchase method is called from
PurchaseService , as shown in Listing 7-53.
The query, shown in Listing 7-53, finds the users being followed by the current user and then matches those users
to a purchase that has been MADE which CONTAINS a product. The return value is a set of properties that identify the
product title, the name of the friend or friends, and the number of friends who have bought the product. The result is
ordered by the number of friends who have purchased the product and then by product title, as shown in Figure 7-14 .
Listing 7-53. The friendsPurchase Method in PurchaseService
public List<MappedProductUserPurchase> friendsPurchase(string userId)
{
return _graphClient.Cypher
.Match("(u:User { userId : {userId} } )-[:FOLLOWS]-(f)-[:MADE]->()-[:CONTAINS]->p")
.WithParam("userId", userId)
.Return(() => Return.As<MappedProductUserPurchase>("{ productId:p.productId,title:p.
title," +
"fullname:collect(f.firstname + ' ' + f.lastname),wordPhrase:null,cfriends:
count(f) } "))
.OrderByDescending("count(f)")
.Results.ToList();
}
 
Search WWH ::




Custom Search