Database Reference
In-Depth Information
Connecting Users
A common feature in social media applications is to allow users to connect to each other through an explicit
relationship. The following sample application uses the directed relationship type called FOLLOWS . By going to the
“Friends” page within the social graph section, you can see the list of the users the current user is following, search for
new friends to follow, add them, and remove friends the current user is following. The UserController contains each
of the methods to control the flow for these features, including friends , searchbyusername , follow, and unfollow .
To display the list of the users the current user is following, the friends method in the UserController calls the
following method in UserService . The following method in UserService , shown in Listing 7-25, creates a list of users
by matching the current user's username with directed relationship FOLLOWS on the variable user . If the list contains
users, it will be returned to the controller and displayed in the right-hand part of the page, as shown in Figure 7-5 . The
display code for showing the list of users can be found in {PROJECTROOT}/Views/User/Friends.cshtml.
Listing 7-25. UserService following Method
// UserService
public List<User> following(string username)
{
List<User> following = _graphClient.Cypher
.Match(" (user { username:{u}})-[:FOLLOWS]->(users) ")
.WithParam("u", username.ToLower())
.Return(users => users.As<User>())
.OrderBy("users.username")
.Results.ToList<User>();
return following;
}
Figure 7-5. The Friends page
 
Search WWH ::




Custom Search