Exemplo n.º 1
0
        /// <summary>
        /// Performs the business logic for adding the Sibling relationship between the person and
        /// the sibling.
        /// </summary>
        public static void AddSibling(PeopleCollection family, Person person, Person sibling)
        {
            // Handle siblings
            if (person.Siblings.Count > 0)
            {
                // Make the siblings siblings to each other.
                foreach (Person existingSibling in person.Siblings)
                {
                    family.AddSibling(existingSibling, sibling);
                }
            }

            if (person.Parents != null)
            {
                switch (person.Parents.Count)
                {
                // No parents
                case 0:
                    family.AddSibling(person, sibling);
                    break;

                // Single parent
                case 1:
                    family.AddSibling(person, sibling);
                    family.AddChild(person.Parents[0], sibling, ParentChildModifier.Natural);
                    break;

                // 2 parents
                case 2:
                    // Add the sibling as a child of the same parents
                    foreach (Person parent in person.Parents)
                    {
                        family.AddChild(parent, sibling, ParentChildModifier.Natural);
                    }

                    family.AddSibling(person, sibling);
                    break;

                default:
                    family.AddSibling(person, sibling);
                    break;
                }
            }
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Performs the business logic for adding the Child relationship between the person and the child.
        /// </summary>
        public static void AddChild(PeopleCollection family, Person person, Person child)
        {
            // Add the new child as a sibling to any existing children
            foreach (Person existingSibling in person.Children)
            {
                family.AddSibling(existingSibling, child);
            }

            switch (person.Spouses.Count)
            {
            // Single parent, add the child to the person
            case 0:
                family.AddChild(person, child, ParentChildModifier.Natural);
                break;

            // Has existing spouse, add the child to the person's spouse as well.
            case 1:
                family.AddChild(person, child, ParentChildModifier.Natural);
                family.AddChild(person.Spouses[0], child, ParentChildModifier.Natural);
                break;
            }
        }