//Consultada sugerencias de un usuario public async Task <List <SuggestionInfo> > getSuggestion(IList <User> users) { string cypher = new StringBuilder() .AppendLine("UNWIND $users AS user") //Identifica usuario .AppendLine("MATCH (myuser:User {id: user.id})") //Traer sugerencias que tiene el usuario .AppendLine("MATCH ((myuser)-[:GET]-(s:Suggestion)-[:SUGGEST]-(u:User))") //Filtrar que no esten desactivados .AppendLine("WHERE NOT(s.isActive = false)") .AppendLine("RETURN u.id, u.name, s.id, s.isActive") .ToString(); var session = client.GetDriver().AsyncSession(o => o.WithDatabase("neo4j")); List <SuggestionInfo> mySuggInfoList = new List <SuggestionInfo>(); try { var reader = await session.RunAsync(cypher, new Dictionary <string, object>() { { "users", ParameterSerializer.ToDictionary(users) } }); while (await reader.FetchAsync()) { int count = 0; string[] aux = new string[3]; foreach (var item in reader.Current.Values) { if (count == 3) { User myuser = new User { Id = aux[0], Name = aux[1] }; Suggestion mySugg = new Suggestion { Id = aux[2], IsActive = (bool)item.Value }; SuggestionInfo SuggInfo = new SuggestionInfo { Suggestion = mySugg, SuggestedUser = myuser }; mySuggInfoList.Add(SuggInfo); } else { aux[count] = item.Value.ToString(); } count++; } } } finally { await session.CloseAsync(); } return(mySuggInfoList); }
/*DB operations*/ //Crea sugerencias de usuario en la base de datos private async Task CreateSuggestion(IList <Suggestion> suggestions) { string cypher = new StringBuilder() .AppendLine("UNWIND $suggestions AS suggestion") .AppendLine("CREATE(:Suggestion{id: suggestion.id, isActive: suggestion.isActive})") .ToString(); var session = client.GetDriver().AsyncSession(o => o.WithDatabase("neo4j")); try { await session.RunAsync(cypher, new Dictionary <string, object>() { { "suggestions", ParameterSerializer.ToDictionary(suggestions) } }); } finally { await session.CloseAsync(); } }
public async Task <string> CreateRelationGatherUser(IList <UserInfo> userMetadata) { var session = client.GetDriver().AsyncSession(o => o.WithDatabase("neo4j")); string cypher = new StringBuilder() .AppendLine("UNWIND $userMetadata AS userMetadata") //Find User .AppendLine("MATCH (u:User { id: userMetadata.user.id })") // User GATHER .AppendLine("WITH userMetadata, u") .AppendLine("UNWIND userMetadata.gathers AS gather") .AppendLine("MATCH (g:User { id: gather.id})") .AppendLine("MERGE (u)-[r:GATHER]-(g)") .AppendLine("RETURN u.name, type(r), g.name") .ToString(); string ans = ""; try { var reader = await session.RunAsync(cypher, new Dictionary <string, object>() { { "userMetadata", ParameterSerializer.ToDictionary(userMetadata) } }); while (await reader.FetchAsync()) { foreach (var item in reader.Current.Values) { ans += item.Value.ToString() + " "; } } } finally { await session.CloseAsync(); } return(ans); }
//Pasa el estado de activado a desactivado public async Task <string> ChangeIsActive(IList <Suggestion> suggestions) { string cypher = new StringBuilder() .AppendLine("UNWIND $suggestions AS suggestion") .AppendLine("MATCH (s:Suggestion {id: suggestion.id})") .AppendLine("SET s.isActive = false") .AppendLine("RETURN s.id, s.isActive") .ToString(); var session = client.GetDriver().AsyncSession(o => o.WithDatabase("neo4j")); string ans = ""; try { var reader = await session.RunAsync(cypher, new Dictionary <string, object>() { { "suggestions", ParameterSerializer.ToDictionary(suggestions) } }); while (await reader.FetchAsync()) { foreach (var item in reader.Current.Values) { ans += item.Value.ToString() + " "; } } } finally { await session.CloseAsync(); } return(ans); }
public async Task <List <Like> > UsersLikes(IList <User> users) { string cypher = new StringBuilder() .AppendLine("UNWIND $users AS user") .AppendLine("MATCH (u:User{id: user.id})") .AppendLine("MATCH (u)-[:LIKE]->(l:Like)") .AppendLine("RETURN l.name") .ToString(); var session = client.GetDriver().AsyncSession(o => o.WithDatabase("neo4j")); List <Like> myLikes = new List <Like>(); try { var reader = await session.RunAsync(cypher, new Dictionary <string, object>() { { "users", ParameterSerializer.ToDictionary(users) } }); System.Console.WriteLine("****user's likes:"); while (await reader.FetchAsync()) { foreach (var item in reader.Current.Values) { Like auxLike = new Like { Name = item.Value.ToString() }; System.Console.WriteLine(item.Value.ToString()); myLikes.Add(auxLike); } } } finally { await session.CloseAsync(); } return(myLikes); }
/*DB operations*/ public async Task <string> CreateUser(IList <User> users) { string cypher = new StringBuilder() .AppendLine("UNWIND $users AS user") .AppendLine("CREATE(u:User{id: user.id, name: user.name})") .AppendLine("RETURN u.id") .ToString(); var session = client.GetDriver().AsyncSession(o => o.WithDatabase("neo4j")); string ans = ""; try { var reader = await session.RunAsync(cypher, new Dictionary <string, object>() { { "users", ParameterSerializer.ToDictionary(users) } }); while (await reader.FetchAsync()) { foreach (var item in reader.Current.Values) { ans += item.Value.ToString(); } } } finally { await session.CloseAsync(); } return(ans); }
public async Task <string> CreateRelationshipLike(IList <LikeInfo> likeMetadata) { string cypher = new StringBuilder() .AppendLine("UNWIND $likeMetadata AS likeMetadata") //find like .AppendLine("MATCH (l:Like { name: likeMetadata.like.name })") //category .AppendLine("WITH likeMetadata, l") .AppendLine("UNWIND likeMetadata.category AS category") .AppendLine("MATCH (c:Category { name: category.name})") .AppendLine("MERGE (l)-[r:IS]->(c)") .AppendLine("RETURN l.name, type(r), c.name") .ToString(); var session = client.GetDriver().AsyncSession(o => o.WithDatabase("neo4j")); string ans = ""; try { var reader = await session.RunAsync(cypher, new Dictionary <string, object>() { { "likeMetadata", ParameterSerializer.ToDictionary(likeMetadata) } }); while (await reader.FetchAsync()) { foreach (var item in reader.Current.Values) { ans += item.Value.ToString() + " "; } } } finally { await session.CloseAsync(); } return(ans); }
public async Task CreateRelationships(IList <MovieInformation> metadatas) { string cypher = new StringBuilder() .AppendLine("UNWIND {metadatas} AS metadata") // Find the Movie: .AppendLine("MATCH (m:Movie { title: metadata.movie.title })") // Create Cast Relationships: .AppendLine("UNWIND metadata.cast AS actor") .AppendLine("MATCH (a:Person { name: actor.name })") .AppendLine("MERGE (a)-[r:ACTED_IN]->(m)") // Create Director Relationship: .AppendLine("WITH metadata, m") .AppendLine("MATCH (d:Person { name: metadata.director.name })") .AppendLine("MERGE (d)-[r:DIRECTED]->(m)") // Add Genres: .AppendLine("WITH metadata, m") .AppendLine("UNWIND metadata.genres AS genre") .AppendLine("MATCH (g:Genre { name: genre.name})") .AppendLine("MERGE (m)-[r:GENRE]->(g)") .ToString(); using (var session = driver.Session()) { await session.RunAsync(cypher, new Dictionary <string, object>() { { "metadatas", ParameterSerializer.ToDictionary(metadatas) } }); } }
public async Task CreateMovies(IList <Movie> movies) { string cypher = new StringBuilder() .AppendLine("UNWIND {movies} AS movie") .AppendLine("MERGE (m:Movie {id: movie.id})") .AppendLine("SET m = movie") .ToString(); using (var session = driver.Session()) { await session.RunAsync(cypher, new Dictionary <string, object>() { { "movies", ParameterSerializer.ToDictionary(movies) } }); } }
public async Task CreateGenres(IList <Genre> genres) { string cypher = new StringBuilder() .AppendLine("UNWIND {genres} AS genre") .AppendLine("MERGE (g:Genre {name: genre.name})") .AppendLine("SET g = genre") .ToString(); using (var session = driver.Session()) { await session.RunAsync(cypher, new Dictionary <string, object>() { { "genres", ParameterSerializer.ToDictionary(genres) } }); } }
public async Task CreatePersons(IList <Person> persons) { string cypher = new StringBuilder() .AppendLine("UNWIND {persons} AS person") .AppendLine("MERGE (p:Person {name: person.name})") .AppendLine("SET p = person") .ToString(); using (var session = driver.Session()) { await session.RunAsync(cypher, new Dictionary <string, object>() { { "persons", ParameterSerializer.ToDictionary(persons) } }); } }