public static ModuleTree BuildTree(IEnumerable <ModuleRPS> results) { // collect nodes var nodes = results.ToDictionary(k => k.ID, v => new ModuleTree( v.Name, new Uri(v.LinkURL, UriKind.Relative), v.ID, v.IsAuthorized, v.SortId, v.ParentId, v.Icon)); // build tree var root = new ModuleTree("root", new Uri("#", UriKind.Relative), 0); foreach (var result in results) { var node = nodes[result.ID]; var parentNode = result.ParentId == 0 ? root : nodes[result.ParentId]; try { parentNode.AddChild(node); } catch (ArgumentException ex) { Logging lg = new Logging(); lg.Error(ex, "Duplicate SortId is found in Module."); } catch (Exception ex) { Logging lg = new Logging(); lg.Error(ex, "Error in Module."); } } return(root); }
public void AddChild(ModuleTree child) { childrens.Add(child.Order, child); }