public IEnumerable <ProductCategoryNode> GetNodes(IEnumerable <ProductCategoryParent> parents) { ProductCategoryNode _newNode; foreach (var _parent in parents) { this._activeNode = null; _newNode = new ProductCategoryNode(); _newNode.No = _parent.No; _newNode.Name = _parent.Name; if (_parent.ParentNo.HasValue == true) { this.SetActiveNode(_nodes, _parent.ParentNo.Value); } if (this._activeNode == null) { this._nodes.Add(_newNode); continue; } else { this._activeNode.AddChildren(_newNode); } } return(this._nodes.ToArray()); }
private void SetActiveNode(IEnumerable <ProductCategoryNode> nodes, int parentNo) { if (this._nodes.Count == 0) { return; } var _matchNode = nodes.Where(x => x.No == parentNo).FirstOrDefault(); if (_matchNode != null) { this._activeNode = _matchNode; return; } foreach (var node in nodes) { if (node.Childrens != null) { this.SetActiveNode(node.Childrens, parentNo); } } }
public void AddChildren(ProductCategoryNode children) { this._children.Add(children); }