public menuWithContent Get(string name = "") { menuWithContent menu = new menuWithContent(); try { CurtDevDataContext db = new CurtDevDataContext(); menu = (from m in db.Menus where m.menu_name.ToLower() == name.ToLower() && m.websiteID.Equals(this.websiteID) select new menuWithContent { menuID = m.menuID, menu_name = m.menu_name, display_name = m.display_name, requireAuthentication = m.requireAuthentication, isPrimary = m.isPrimary, active = m.active }).First<menuWithContent>(); List<menuItem> contents = (from msc in db.Menu_SiteContents where msc.menuID.Equals(menu.menuID) && ((msc.menuTitle != null && msc.menuLink != null) || (msc.contentID != null && (db.SiteContents.Where(x => x.contentID == msc.contentID).Where(x => x.published == true)).Single() != null)) orderby msc.parentID, msc.menuSort select new menuItem { menuContentID = msc.menuContentID, menuID = msc.menuID, menuSort = msc.menuSort, menuTitle = msc.menuTitle, menuLink = msc.menuLink, linkTarget = msc.linkTarget, parentID = msc.parentID, contentID = msc.contentID, content = (from sc in db.SiteContents where sc.contentID.Equals(msc.contentID) select new ContentPage { contentID = sc.contentID, page_title = sc.page_title, content_type = sc.content_type, lastModified = sc.lastModified, createdDate = sc.createdDate, published = sc.published, meta_title = sc.meta_title, meta_description = sc.meta_description, keywords = sc.keywords, active = sc.active, isPrimary = sc.isPrimary, slug = sc.slug, revision = (db.SiteContentRevisions.Where(x => x.contentID == sc.contentID).Where(x => x.active == true).First<SiteContentRevision>()) }).FirstOrDefault<ContentPage>() }).ToList<menuItem>(); menu.contents = contents.ToLookup(k => (k.parentID == null) ? 0 : k.parentID); return menu; } catch { return menu; } }
public static string generateMenu(menuWithContent menu, int parentid) { string pagecontent = "<ul>"; List<menuItem> menuitems = menu.getChildren(parentid); foreach (menuItem menuitem in menuitems) { pagecontent += "<li>"; if (menuitem.hasContent()) { pagecontent += "<a href='/page/" + menu.menuID + "/" + menuitem.content.slug + "' >" + menuitem.content.page_title + "</a>"; } else { pagecontent += "<a " + ((menuitem.linkTarget) ? "target=_blank" : "") + " href='" + menuitem.menuLink + "'>" + menuitem.menuTitle + "</a>"; } if (menu.hasChildren(menuitem.menuContentID)) { pagecontent += generateMenu(menu, menuitem.menuContentID); } pagecontent += "</li>"; } pagecontent += "</ul>"; return pagecontent; }