// POST: api/Relationship //BODY: {"From" : "Bob","To" : "Charlie","Type" : "Classmate"} //Create a relationship public HttpResponseMessage Post([FromBody] CustomRelationship r) { service = new Neo4jRelationshipApiService(ServerUri, Username, Password); var result = service.CreateRelationship(r); if (result) { return(Request.CreateResponse(HttpStatusCode.Created, "Created")); } else { return(Request.CreateResponse(HttpStatusCode.OK, "Failed")); } }
//Get specific relationship public List <CustomRelationship> GetRelationships(string type) { List <CustomRelationship> RelationshipList = null; try { using (var session = driver.Session()) { RelationshipList = new List <CustomRelationship>(); var relations = session.ReadTransaction(tx => { var res = tx.Run($"MATCH p=()-[r:RELATIONSHIP]->() WHERE r.type = \"{type}\" RETURN p"); return(res); }); foreach (var record in relations) { var relationProps = JsonConvert.SerializeObject(record[0].As <IPath>().Relationships[0].Properties); var rl = JsonConvert.DeserializeObject <Relationship>(relationProps); var startnodeProps = JsonConvert.SerializeObject(record[0].As <IPath>().Start.Properties); var startnode = JsonConvert.DeserializeObject <Student>(startnodeProps); var endnodeProps = JsonConvert.SerializeObject(record[0].As <IPath>().End.Properties); var endnode = JsonConvert.DeserializeObject <Student>(endnodeProps); CustomRelationship cr = new CustomRelationship(); cr.Type = rl.Type; cr.From = startnode.name; cr.To = endnode.name; RelationshipList.Add(cr); } } } catch (Exception ex) { RelationshipList = null; } return(RelationshipList); }