public static async Task <MinimalRecipe> Get(string uid) { MinimalRecipe u = null; var session = new Database("bolt://db:7687", "neo4j", "APPmvc").session(); try { await session.ReadTransactionAsync(async tx => { var reader = await tx.RunAsync("Match(u:Recipe) Where u.id = $guid Return u", new { guid = uid }); u = new MinimalRecipe(); while (await reader.FetchAsync()) { var aa = reader.Current[0].As <INode>().Properties; foreach (var(key, value) in aa) { u.GetType().GetProperty(key)?.SetValue(u, value, null); } } }); } catch { // ignored } finally { await session.CloseAsync(); } return(u); }
public static async Task Add(MinimalRecipe r) { MinimalRecipe u; var session = new Database("bolt://db:7687", "neo4j", "APPmvc").session(); try { await session.WriteTransactionAsync(async tx => { var reader = await tx.RunAsync("Merge (i:Recipe {title: $title, id: $id, image: $image}) " + "return i", new { r.id, r.image, r.title }); u = new MinimalRecipe(); while (await reader.FetchAsync()) { var aa = reader.Current[0].As <INode>().Properties; foreach (var(key, value) in aa) { u.GetType().GetProperty(key)?.SetValue(u, value, null); } } }); } catch { // ignored } finally { await session.CloseAsync(); } }
public static async Task <List <MinimalRecipe> > GetStared(string user) { var session = new Database("bolt://db:7687", "neo4j", "APPmvc").session(); var lst = new List <MinimalRecipe>(); try { await session.ReadTransactionAsync(async tx => { var reader = await tx.RunAsync("Match(u:User)-[:REC]->(z:Recipe) " + "where u._email = $user " + "return z", new { user }); while (await reader.FetchAsync()) { var r = new MinimalRecipe(); var aa = reader.Current[0].As <INode>().Properties; foreach (var(key, value) in aa) { r.GetType().GetProperty(key)?.SetValue(r, value, null); } lst.Add(r); } }); } catch { // ignored } finally { await session.CloseAsync(); } return(lst); }