private void AddPedigreeUnit (HorsePedigreeDTO child, HorsePedigreeDTO item, ICollection <PedigreeUnit> newPedigree) { var itemNewPedigree = newPedigree.FirstOrDefault(x => x.IdNumber.Equals(item.Item.IdNumber)); var isNew = itemNewPedigree == null; if (isNew) { itemNewPedigree = new PedigreeUnit() { ItemId = Guid.NewGuid(), IdNumber = item.Item.IdNumber, Name = item.Item.Name }; } if (child != null) { var childNewPedigree = newPedigree.FirstOrDefault(x => x.IdNumber.Equals(child.Item.IdNumber)); if (childNewPedigree != null && !itemNewPedigree.Children.Any(x => x.ItemId.Equals(childNewPedigree.ItemId))) { itemNewPedigree.Children.Add(childNewPedigree); } } if (isNew) { newPedigree.Add(itemNewPedigree); } }
private void ProceedParents (PedigreeUnit root, ICollection <PedigreeUnit> pedigree, PedigreePath path, ICollection <PedigreePath> paths) { var parents = pedigree.Where(x => x.Children.Any(y => y.ItemId.Equals(root.ItemId))).ToList(); if (!parents.Any()) { paths.Add(path); } foreach (var parent in parents) { var currentPath = path.Copy(); currentPath.AddNode(new PedigreePathNode() { Id = parent.ItemId, Name = parent.Name }); ProceedChildren(root, parent, currentPath, paths); ProceedParents(parent, pedigree, currentPath, paths); } }
private void ProceedChildren(PedigreeUnit chosenChild, PedigreeUnit parent, PedigreePath path, ICollection <PedigreePath> paths) { if (!parent.Children.Any()) { paths.Add(path); } foreach (var child in parent.Children) { if (child.ItemId.Equals(chosenChild.ItemId)) { continue; } var currentPath = path.Copy(); currentPath.AddNode(new PedigreePathNode() { Id = child.ItemId, Name = child.Name }); ProceedChildren(parent, child, currentPath, paths); } }