Example #1
0
        static void Main(string[] args)
        {
            using (var context = new LohasContext())
            {
                
                context.Systems_SiteMap.Add(new Systems_SiteMap
                {
                    ID = Guid.NewGuid(),
                    Title = "Forms",
                    Description = "Forms",
                    ParentID = Guid.Empty
                });

                context.Systems_SiteMap.Add(new Systems_SiteMap
                {
                    ID = Guid.NewGuid(),
                    Title = "Charts",
                    Description = "Charts",
                    ParentID = Guid.Empty
                });

                context.Systems_SiteMap.Add(new Systems_SiteMap
                {
                    ID = Guid.NewGuid(),
                    Title = "Tables",
                    Description = "Tables",
                    ParentID = Guid.Empty
                });

                context.Systems_SiteMap.Add(new Systems_SiteMap
                {
                    ID = Guid.NewGuid(),
                    Title = "Bootstrap Elements",
                    Description = "Bootstrap Elements",
                    ParentID = Guid.Empty
                });

                context.Systems_SiteMap.Add(new Systems_SiteMap
                {
                    ID = Guid.NewGuid(),
                    Title = "Bootstrap Grid",
                    Description = "Bootstrap Grid",
                    ParentID = Guid.Empty
                });


                context.Systems_SiteMap.Add(new Systems_SiteMap
                {
                    ID = Guid.NewGuid(),
                    Title = "Dropdown",
                    Description = "Dropdown",
                    ParentID = Guid.Empty
                });

                context.SaveChanges();
            }
            Console.ReadLine();
        }
        public override SiteMapNodeCollection GetChildNodes(SiteMapNode node)
        {
            lock (this)
            {
                using (var context = new LohasContext())
                {
                    var maps = context.Systems_SiteMap.Where(p=>p.ParentID.ToString()==node.Key).OrderBy(p => p.ID).ToList();
                    foreach (var item in maps)
                    {
                        AddNode(CreateSiteMapFromRow(item), node);
                    }
                }

               // return _root;
            }
            return base.GetChildNodes(node);
        }
 public override SiteMapNode BuildSiteMap()
 {
     lock (this)
     {
         if (_root != null)
             return _root;
         using (var context=new LohasContext())
         {
             var maps = context.Systems_SiteMap.OrderBy(p => p.ID).ToList();
             foreach (var item in maps)
             {
                 if (item.Equals(maps.First()))
                 {
                     if(item.ParentID==Guid.Empty) 
                     _root = CreateSiteMapFromRow(item);
                     AddNode(_root, null);
                 }
                 else
                 {
                     SiteMapNode node = CreateSiteMapFromRow(item);
                     AddNode(node, GetParentNodeFromNode(item));
                 }
             }
         }
         
         return _root;
     }
 }