Database Reference
In-Depth Information
User Controller
The UserController class contains a method called Edit , which takes the User object argument. The “Sign-Up” and
“Login” examples use the GraphStory object to pass through values. This example demonstrates another way to pass
values into the back-end code (Listing 7-23).
Notice that the User object is converted from a JSON string and returns a User object as Json. The response could
be used to update the form elements, but because the values are already set within the form there is no need to update
the values. In this case, the application uses the JSON response to let the user know if the update succeeded or not via
a standard JavaScript alert message.
Listing 7-23. UserController Edit Method
public JsonResult Edit(User user)
{
user.username = graphstoryUserAuthValue;
graphStoryService.userInterface.update(user);
return Json(User);
}
User Update Method
To complete the update, the Edit method calls the update method in UserService layer. Because the object being
passed into the update method did nothing more than modify the first and last name of an existing entity, you can use
the SET clause via Cypher to update the properties in the graph, as shown in Listing 7-24. This Cypher statement also
uses the WithParams clause, which requires an array of parameter objects as its argument, to pass the updated values
to the SET clause.
Listing 7-24. Update Method for a User
public User update(User user)
{
_graphClient.Cypher
.Match(" (user:User {username:{user}} ) ")
.WithParam("user", user.username.ToLower())
.Set("user.firstname = {fn}, user.lastname = {ln} ")
.WithParams(new {fn=user.firstname,ln=user.lastname })
.ExecuteWithoutResults();
return user;
}
each of the controllers and the front-end code make use of similar syntax. the next and subsequent sections
will therefore not feature the controller and front-end code and instead focus on the Neo4jClient aspects of the
application. the controllers and front-end code will be referenced, but not listed directly in the following sections.
Note
 
 
Search WWH ::




Custom Search