Beispiel #1
0
        private static RenderPage CreateTree(WebPage[] pages, WebPage current = null)
        {
            Dictionary<int, Node<WebPage>> lookup = new Dictionary<int, Node<WebPage>>();
            Dictionary<int?, List<Node<WebPage>>> children = new Dictionary<int?, List<Node<WebPage>>>();

            List<Node<WebPage>> roots = new List<Node<WebPage>>();

            foreach (var page in pages)
            {
                Node<WebPage> node = new Node<WebPage>();
                node.Data = page;
                node.Children = new List<Node<WebPage>>();

                lookup.Add(page.Id, node);

                if (page.ParentId != null)
                {
                    if (!children.ContainsKey(page.ParentId))
                    {
                        children[page.ParentId] = new List<Node<WebPage>>();
                    }
                    children[page.ParentId].Add(node);
                }

                if (page.ParentId == null)
                {
                    node.Parent = null;
                    roots.Add(node);
                }
            }

            foreach (var node in lookup.Values)
            {
                var page = node.Data;
                Node<WebPage> parent = null;
                if (page.ParentId != null)
                {
                    parent = lookup[(int)page.ParentId];
                }
                node.Parent = parent;
                if (children.ContainsKey(page.Id))
                {
                    node.Children = children[page.Id];
                }
            }

            var rpage = new RenderPage();
            rpage.Roots = roots;
            rpage.lookup = lookup;
            rpage.children = children;
            if (current != null)
            {
                rpage.Page = lookup[current.Id];
                rpage.Sidebar = GetFirstAncestor(rpage.Page);
                rpage.Ancestors = GetAncestors(rpage.Page);
                rpage.Title = rpage.Page.Data.Title;
            }
            return rpage;
        }
Beispiel #2
0
        public ActionResult Create(WebPage webpage, string nextStep)
        {
            this.ValidateRequest = false;
            if (ModelState.IsValid)
            {
                db.WebPages.Add(webpage);
                db.SaveChanges();
                return Redirect(nextStep);
            }

            ViewBag.ParentId = new SelectList(db.WebPages, "Id", "Url", webpage.ParentId);
            CreateFrame(title);
            return View(webpage);
        }
Beispiel #3
0
 //
 // GET: /AdminWebPage/Create
 public ActionResult Create(int? id)
 {
     CreateFrame(title);
     var parent = db.WebPages.Find(id);
     ViewBag.ParentId = new SelectList(db.WebPages, "Id", "Url", id);
     var page = new WebPage();
     page.Active = true;
     page.InNavigation = true;
     page.Col = 2;
     if (parent != null)
     {
         page.Url = parent.Url + "/";
     }
     return View(page);
 }
Beispiel #4
0
        public ActionResult Detail(int? id)
        {
            if (id == null)
            {
                id = db.Press.OrderByDescending(p => p.CreatedDate).Last().Id;
            }
            var article = db.Press.Include("Category").First(p => p.Id == id);
            var url = string.Format("press/{0}", article.Category.Slug);
            var rpage = RenderPage.Create(db, url, article.Title);

            var pressPage = new WebPage();
            pressPage.Title = article.Title;
            var pressNode = new Node<WebPage>();
            pressNode.Data = pressPage;
            rpage.Ancestors.Add(pressNode);

            ViewBag.article = article;

            return View(rpage);
        }
Beispiel #5
0
 public ActionResult Edit(WebPage webpage, string nextStep)
 {
     this.ValidateRequest = false;
     if (ModelState.IsValid)
     {
         db.Entry(webpage).State = EntityState.Modified;
         db.SaveChanges();
         return Redirect(nextStep);
     }
     ViewBag.ParentId = new SelectList(db.WebPages, "Id", "Url", webpage.ParentId);
     return View(webpage);
 }
Beispiel #6
0
        public ActionResult StyleDetail(string slug)
        {
            var style = db.Styles.First(c => c.Slug == slug.ToLower());
            var rpage = RenderPage.Create(db, "product/style", style.Name);

            var pressPage = new WebPage();
            pressPage.Title = style.Name;
            var pressNode = new Node<WebPage>();
            pressNode.Data = pressPage;
            rpage.Ancestors.Insert(0, pressNode);

            ViewBag.style = style;

            return View(rpage);
        }