private List<string> CreateUrl(List<string> url, Page page) { url.Add(page.UrlName); if (page.ParentPage != null) CreateUrl(url, page.ParentPage); return url; }
private void BuildPageTree(Page page, int level) { foreach (var p in page.Pages) { _pageTree.Add(new PageTree { Url = GetUrl(page) + p.UrlName, LevelName = GetLevel(level) + p.Name, Name = p.Name, ID = p.ID }); if (p.Pages.Any()) BuildPageTree(p, level + 1); } }
public ActionResult Page(Page page, string btnSubmit, bool? usedirecturl) { if (string.IsNullOrEmpty(page.Name)) { TempData["error"] = new Dictionary<string, string> { { "Name", "Namn krävs" } }; return Redirect("/admin/page/" + page.ID); } var p = _site.Pages.FirstOrDefault(x => x.ID == page.ID) ?? new Page(); switch (btnSubmit) { case "Spara": var parentpage = page.ParentPage.ID == 0 ? null : _site.Pages.Single(x => x.ID == page.ParentPage.ID); p.ParentPage = parentpage; p.DirectUrl = (usedirecturl != null && (bool)usedirecturl) ? page.DirectUrl : ""; p.VisibleInMenu = page.VisibleInMenu; p.DemandUserInRole = page.DemandUserInRole; if (p.ID == 0) p.SortOrder = parentpage == null ? _site.Pages.Any() ? _site.Pages.Max(x => x.SortOrder) + 1 : 1 : parentpage.Pages.Any() ? parentpage.Pages.Max(x => x.SortOrder) + 1 : 1; if (p.ID == 0) p.Template = _site.Templates.Single(x => x.ID == page.Template.ID); p.UrlName = NameToUrlName(page.Name); p.Name = page.Name; if (p.ID == 0) _site.Pages.Add(p); Save(); TempData["message"] = new List<string> { "Sidan " + p.Name + " är skapad" }; return Redirect("/admin/page/" + page.ID); default: if (p.ParentPage != null) { var i = 1; foreach (var page1 in p.ParentPage.Pages.Where(x => x.ID != p.ID).OrderBy(x => x.SortOrder)) { page1.SortOrder = i; i++; } } else { int i = 1; foreach (var page1 in _site.Pages.Where(x => x.ID != p.ID && x.ParentPage == null).OrderBy(x => x.SortOrder)) { page1.SortOrder = i; i++; } } _ctx.Pages.Remove(p); _ctx.SaveChanges(); TempData["message"] = new List<string> { "Sidan " + p.Name + " är borttagen" }; return Redirect("/admin"); } }
private string GetUrl(Page page) { _url += page.UrlName + "/"; if (page.ParentPage != null) GetUrl(page.ParentPage); var s = _url; _url = "/"; return s; }