Ejemplo n.º 1
0
        public async Task UpdateNode(PersonFamilyTreeNode oldNode, PersonFamilyTreeNode newNode)
        {
            var client = await Neo4JConnection.GetClient();

            var txClient = (ITransactionalGraphClient)client;

            using (var transaction = txClient.BeginTransaction())
            {
                try
                {
                    var children = await GetChildren(oldNode.Id);
                    await DeleteNode(client, oldNode);
                    await AddNewNode(client, newNode);
                    await ReacreateRelationships(newNode, client, children);

                    await transaction.CommitAsync();
                }
                catch (Exception e)
                {
                    await transaction.RollbackAsync();

                    throw e;
                }
            }
        }
Ejemplo n.º 2
0
 private static async Task ReacreateRelationships(PersonFamilyTreeNode newNode, Neo4jClient.GraphClient client, List <string> children)
 {
     foreach (var child in children)
     {
         await CreateParentRelationship(client, newNode.Id, child);
         await CreateChildRelationship(client, newNode.Id, child);
     }
 }
Ejemplo n.º 3
0
 private async static Task DeleteNode(Neo4jClient.GraphClient client, PersonFamilyTreeNode personFamilyTreeNode)
 {
     await client.Cypher.Match("(a:Person)")
     .Where("a.Id = $id")
     .WithParam("id", personFamilyTreeNode.Id)
     .DetachDelete("a")
     .ExecuteWithoutResultsAsync();
 }
Ejemplo n.º 4
0
 private async static Task CreateNode(Neo4jClient.GraphClient client, PersonFamilyTreeNode personFamilyTreeNode)
 {
     await client.Cypher.Create("(n:Person { Id: $id, Name: $name, FatherId: $fatherId, MotherId: $motherId })")
     .WithParam("id", personFamilyTreeNode.Id)
     .WithParam("name", personFamilyTreeNode.Name)
     .WithParam("fatherId", personFamilyTreeNode.FatherId)
     .WithParam("motherId", personFamilyTreeNode.MotherId)
     .ExecuteWithoutResultsAsync();
 }
Ejemplo n.º 5
0
        public async Task Handle(PersonCreatedEvent @event)
        {
            var personFamilyTreeNode = new PersonFamilyTreeNode()
            {
                Id       = @event.Person.Id,
                Name     = @event.Person.Name,
                FatherId = @event.Person.FatherId,
                MotherId = @event.Person.MotherId
            };

            await PersonFamilyTreeRepository.AddNode(personFamilyTreeNode);
        }
Ejemplo n.º 6
0
        private static async Task AddNewNode(Neo4jClient.GraphClient client, PersonFamilyTreeNode personFamilyTreeNode)
        {
            var idFather = personFamilyTreeNode.FatherId;
            var idMother = personFamilyTreeNode.MotherId;
            var idChild  = personFamilyTreeNode.Id;

            await CreateNode(client, personFamilyTreeNode);
            await CreateParentRelationship(client, idFather, idChild);
            await CreateChildRelationship(client, idFather, idChild);
            await CreateParentRelationship(client, idMother, idChild);
            await CreateChildRelationship(client, idMother, idChild);
        }
Ejemplo n.º 7
0
        public async Task RemoveNode(PersonFamilyTreeNode personFamilyTreeNode)
        {
            var client = await Neo4JConnection.GetClient();

            var txClient = (ITransactionalGraphClient)client;

            using (var transaction = txClient.BeginTransaction())
            {
                try
                {
                    await DeleteNode(client, personFamilyTreeNode);

                    await transaction.CommitAsync();
                }
                catch (Exception e)
                {
                    await transaction.RollbackAsync();

                    throw e;
                }
            }
        }
        public async Task Handle(PersonUpdatedEvent @event)
        {
            if (HasChangedParents(@event))
            {
                var oldNode = new PersonFamilyTreeNode()
                {
                    Id       = @event.OldPersonData.Id,
                    Name     = @event.OldPersonData.Name,
                    FatherId = @event.OldPersonData.FatherId,
                    MotherId = @event.OldPersonData.MotherId
                };

                var newNode = new PersonFamilyTreeNode()
                {
                    Id       = @event.NewPersonData.Id,
                    Name     = @event.NewPersonData.Name,
                    FatherId = @event.NewPersonData.FatherId,
                    MotherId = @event.NewPersonData.MotherId
                };

                await PersonFamilyTreeRepository.UpdateNode(oldNode, newNode);
            }
        }