/// <summary> /// Tests to see if this is a child of the supplied parent url / level combination /// </summary> ///<param name="parent">the parent node to consider</param> /// <returns>true if this is a direct child node, else false</returns> internal bool IsDirectChildOfUrl(TitleRankNode parent) { if (parent._truelevel != (this._truelevel - 1)) { return false; } string tempurlstring = parent.Url; if (!parent.Url.EndsWith(Shared.Whack.ToString())) { tempurlstring += Shared.Whack; } //if this is the next level down and we start with the parent url then this must be a child, else not return Url.StartsWith(tempurlstring, StringComparison.InvariantCultureIgnoreCase); }
/// <summary> /// Adds the child to the collection and reorders it (applying the appropriate sibling number) /// order is based on url. /// If this child is already the child of another row an exception will be thrown /// </summary> /// <param name="child">the child to add. will have properties updated.</param> /// <param name="siblingStartingNumber">optional starting number defaulting to 1, used for level 1s as they need to mix with home nodes</param> internal void AddChild(ref TitleRankNode child, int siblingStartingNumber = 1) { if (child.Parent != null && child.Parent != this) { throw new Exception(Shared.GetParentMismatchExceptionMessageStringFormat(child.RowNumber, child.Parent.RowNumber, this.RowNumber)); } Children.Add(child); child.Parent = this; child.ParentId = this.Id; Children = Children.OrderBy(x => x.Url).ToList(); int count = siblingStartingNumber; //1 based counting for ids foreach (var c in Children) { c.SiblingNumber = count; count++; } }