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 static IEnumerable <HorsePedigreeDTO> ParseStringToPedigree(string pedigreeCode) { var pedigreeCodeParsed = pedigreeCode.Split(',', StringSplitOptions.RemoveEmptyEntries); var result = new List <HorsePedigreeDTO>(); for (int i = 0; i < pedigreeCodeParsed.Length; i++) { var item = new HorsePedigreeDTO() { PedigreePosition = _positions[i], Item = _items[pedigreeCodeParsed[i]] }; result.Add(item); } return(result); }
private void ProceedParents (HorsePedigreeDTO root, ICollection <HorsePedigreeDTO> pedigree, ICollection <PedigreeUnit> target, HorsePedigreeDTO child) { AddPedigreeUnit(child, root, target); var father = pedigree.FirstOrDefault(x => x.PedigreePosition.Equals(root.PedigreePosition + "F")); if (father != null) { ProceedParents(father, pedigree, target, root); } var mother = pedigree.FirstOrDefault(x => x.PedigreePosition.Equals(root.PedigreePosition + "M")); if (mother != null) { ProceedParents(mother, pedigree, target, root); } }