Ejemplo n.º 1
0
        private void AddSpouseRelationship(Relationship edge)
        {
            PersonRelationships sourcePersonRelationships, targetPeopleRelationships;

            if (!Families.TryGetValue(edge.Source, out sourcePersonRelationships))
            {
                sourcePersonRelationships = new PersonRelationships();
                Families.Add(edge.Source, sourcePersonRelationships);
            }
            if (!Families.TryGetValue(edge.Target, out targetPeopleRelationships))
            {
                targetPeopleRelationships = new PersonRelationships();
                Families.Add(edge.Target, targetPeopleRelationships);
            }

            if (targetPeopleRelationships.Spouse == null && sourcePersonRelationships.Spouse == null)
            {
                targetPeopleRelationships.AddSpouse(edge.Source);
                sourcePersonRelationships.AddSpouse(edge.Target);
            }
            else
            {
                throw new InvalidOperationException($"Cannot add spouse");
            }
        }
Ejemplo n.º 2
0
        private void AddParentRelationship(Relationship edge)
        {
            PersonRelationships sourcePersonRelationships, targetPeopleRelationships;

            if (!Families.TryGetValue(edge.Source, out sourcePersonRelationships))
            {
                sourcePersonRelationships = new PersonRelationships();
                Families.Add(edge.Source, sourcePersonRelationships);
            }
            if (!Families.TryGetValue(edge.Target, out targetPeopleRelationships))
            {
                targetPeopleRelationships = new PersonRelationships();
                Families.Add(edge.Target, targetPeopleRelationships);
            }

            if (targetPeopleRelationships.CanAddParent(edge.Source))
            {
                targetPeopleRelationships.AddParent(edge.Source);
                sourcePersonRelationships.AddEdge(edge);
            }
            else
            {
                throw new InvalidOperationException($"Cannot add parents to {edge.Target.Name}");
            }
        }
Ejemplo n.º 3
0
        public IEnumerable <Person> Spouse(Person person)
        {
            List <Person>       result = new List <Person>();
            PersonRelationships personRelationships = GetRelationship(person);

            if (personRelationships.Spouse != null)
            {
                result.Add(personRelationships.Spouse);
            }
            return(result);
        }
Ejemplo n.º 4
0
        public IEnumerable <Person> Children(Person person, Gender?gender = null)
        {
            List <Person>       result = new List <Person>();
            PersonRelationships personRelationships = GetRelationship(person);
            List <Person>       children            = personRelationships.Edges
                                                      .Where(m => m.RelationshipType == RelationshipType.Parent)
                                                      .Where(m => gender == null || m.Target.Gender == gender)
                                                      .Select(m => m.Target)
                                                      .ToList();

            result.AddRange(children);
            return(result);
        }
Ejemplo n.º 5
0
        public IEnumerable <Person> Parents(Person person, Gender?gender = null)
        {
            List <Person>       result = new List <Person>();
            PersonRelationships personRelationships = GetRelationship(person);

            if (personRelationships == null)
            {
                return(result);
            }
            IEnumerable <Person> parents = personRelationships.Parents
                                           .Where(m => gender == null || m.Gender == gender);

            result.AddRange(parents);
            return(result);
        }