Database Reference
In-Depth Information
public string city { get; set; }
public string state { get; set; }
public string zip { get; set; }
public double lat { get; set; }
public double lon { get; set; }
}
The
User
object also contains a relationship to
Location
via the HAS relationship type.
User
locations are
retrieved through the
getUserLocation
method, shown in Listing 7-46, which is located in the
UserService
class.
Listing 7-46 also provides the ViewModel object named MappedUserLocation, which returns the necessary properties
for the Location view layer.
Listing 7-46.
getUserLocation
in
UserService
public MappedUserLocation getUserLocation(string currentusername)
{
MappedUserLocation mappedUserLocation = _graphClient.Cypher
.Match(" (u:User { username : {u} } )-[:HAS]-(l:Location) ")
.WithParam("u", currentusername)
.Return(() => Return.As<MappedUserLocation>("{ username: u.username, address:
l.address," +
" city:l.city, state: l.state, zip: l.zip, lat: l.lat, lon: l.lon} "))
.Results.First();
return mappedUserLocation;
}
public class MappedUserLocation
{
public string username { get; set; }
public string address { get; set; }
public string city { get; set; }
public string state { get; set; }
public string zip { get; set; }
public double lat { get; set; }
public double lon { get; set; }
}
Search for Nearby Locations
To search for nearby locations, as shown in Figure
7-12
, use the current user's location, obtained with
getUserLocation
, and then the
returnLocationsWithinDistance
(Listing 7-47) to provide the location information
and the type of location being requested. The
returnLocationsWithinDistance
method in
LocationService
also
uses a method called
addDistanceTo
to place a string value of the distance between the starting point and the
respective location.