/// <summary> /// Builds a JsnoItem with: /// /// - The name of the person as the root node /// - His/her parent's marriage as a child node /// - From the marriage node: /// * Add the deep node from the father /// * Add the deep node from the mother /// /// </summary> private JsonItem GetDeepNode(Person person) { if (_processed.ContainsKey(person)) { return(new JsonItem(_processed[person])); } var personNode = new JsonItem(Utils.GetPersonDescription(person)); _processed.Add(person, personNode); var sonOf = _sons.Where(x => x.person_id == person.id).SingleOrDefault(); if (sonOf != null) { var marriage = _marriages.Where(x => x.id == sonOf.marriage_id).Single(); var father = _persons.Where(x => x.id == marriage.husband_id).SingleOrDefault(); var mother = _persons.Where(x => x.id == marriage.wife_id).SingleOrDefault(); var marriageNode = new JsonItem(Utils.GetMarriageDescription(marriage)); personNode.AddChild(marriageNode); var fatherNode = default(JsonItem); if (father != null) { fatherNode = GetDeepNode(father); } else { fatherNode = new JsonItem($"{Utils.MaleSignStr} (unknown)"); } marriageNode.AddChild(fatherNode); var motherNode = default(JsonItem); if (mother != null) { motherNode = GetDeepNode(mother); } else { motherNode = new JsonItem($"{Utils.FemaleSignStr} (unknown)"); } marriageNode.AddChild(motherNode); } return(personNode); }