示例#1
0
        /// <summary>
        /// Gets the combination of parent sets for this person and his/her spouses
        /// </summary>
        /// <returns></returns>
        public ParentSetCollection MakeParentSets()
        {
            ParentSetCollection parentSets = new ParentSetCollection();

            foreach (Person spouse in Spouses)
            {
                ParentSet ps = new ParentSet(this, spouse);

                // Don't add the same parent set twice.
                if (!parentSets.Contains(ps))
                {
                    parentSets.Add(ps);
                }
            }

            return(parentSets);
        }
示例#2
0
        /// <summary>
        /// Performs the business logic for adding the Parent relationship between the person and the parents.
        /// </summary>
        public static void AddParent(PeopleCollection family, Person person, ParentSet parentSet)
        {
            // First add child to parents.
            family.AddChild(parentSet.FirstParent, person, ParentChildModifier.Natural);
            family.AddChild(parentSet.SecondParent, person, ParentChildModifier.Natural);

            // Next update the siblings. Get the list of full siblings for the person.
            // A full sibling is a sibling that has both parents in common.
            List <Person> siblings = GetChildren(parentSet);

            foreach (Person sibling in siblings)
            {
                if (sibling != person)
                {
                    family.AddSibling(person, sibling);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Return a list of children common to both parents in the parent set.
        /// </summary>
        private static List <Person> GetChildren(ParentSet parentSet)
        {
            // Get list of both parents.
            List <Person> firstParentChildren  = new List <Person>(parentSet.FirstParent.Children);
            List <Person> secondParentChildren = new List <Person>(parentSet.SecondParent.Children);

            // Combined children list that is returned.
            List <Person> children = new List <Person>();

            // Go through and add the children that have both parents.
            foreach (Person child in firstParentChildren)
            {
                if (secondParentChildren.Contains(child))
                {
                    children.Add(child);
                }
            }

            return(children);
        }
        /// <summary>
        /// Performs the business logic for changing the person parents
        /// </summary>
        public static void ChangeParents(PeopleCollection family, Person person, ParentSet newParentSet)
        {
            // Don't do anything if there is nothing to change or if the parents are the same
            if (person.ParentSet == null || newParentSet == null || person.ParentSet.Equals(newParentSet))
            {
                return;
            }

            // store the current parent set which will be removed
            ParentSet formerParentSet = person.ParentSet;

            // Remove the first parent
            RemoveParentChildRelationship(person, formerParentSet.FirstParent);

            // Remove the person as a child of the second parent
            RemoveParentChildRelationship(person, formerParentSet.SecondParent);

            // Remove the sibling relationships
            RemoveSiblingRelationships(person);

            // Add the new parents
            AddParent(family, person, newParentSet);
        }