Exemple #1
0
        public Node <Person> AddPotentialFriend(Person main, Person friend, EnterType type)
        {
            Logger.Out("Adding potential friend to DB: {0}", MessageType.Debug, friend.Url);

            var friendNode = db.Cypher
                             .Merge("(person:Person { Id: {id} })")
                             .OnCreate()
                             .Set("person = {friend}")
                             .WithParams(new
            {
                id = friend.Id,
                friend
            }).Return(person => person.Node <Person>())
                             .Results
                             .Single();

            //create
            db.Cypher
            .Match("(mainPerson:Person)", "(friendPerson:Person)")
            .Where((Person mainPerson) => mainPerson.Id == main.Id)
            .AndWhere((Person friendPerson) => friendPerson.Id == friend.Id)
            .CreateUnique("mainPerson-[:" + RelationString.ToString(type) + "]->friendPerson")
            .ExecuteWithoutResults();

            return(friendNode);
        }
Exemple #2
0
 public void AddRelation(Person main, Person friend, EnterType type)
 {
     Logger.Out("Adding relation(Ids): {0} --> {1}", MessageType.Debug, main.Id, friend.Id);
     //create
     _db.Cypher
     .Match("(mainPerson:Person)", "(friendPerson:Person)")
     .Where((Person mainPerson) => mainPerson.Id == main.Id)
     .AndWhere((Person friendPerson) => friendPerson.Id == friend.Id)
     .CreateUnique("mainPerson-[:" + RelationString.ToString(type) + "]->friendPerson")
     .ExecuteWithoutResults();
 }
Exemple #3
0
 public Person[] GetUsersRelated(int userId, EnterType type)
 {
     //match (m:Person{Id:169033204})--(f) return f
     try
     {
         var query = _db
                     .Cypher
                     .Match("(m:Person { Id: {id},Deleted:false})-[:" + RelationString.ToString(type) + "]-(f)")
                     .WithParams(new
         {
             id = userId
         }
                                 )
                     .Return(f => f.As <Person>());
         var res = query.Results.ToArray();
         return(res);
     }
     catch (Exception ex)
     {
         Logger.Out("Query error: {0}", MessageType.Error, ex.Message);
         return(null);
     }
 }