public string ListAllUserPages(string userId, string ctrl) { JavaScriptSerializer js = new JavaScriptSerializer(); string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey")); //if (ctrl != crlHash) return js.Serialize(""); db_config_page dcp = null; try { // first validation to guarantee that user is greater than zero int auxUserId = Convert.ToInt32(userId); if (auxUserId < 0) return js.Serialize(""); dcp = new db_config_page(); dcp.Open(); db_config_users dcu = new db_config_users(dcp.Db, auxUserId); dcu.Open(); // list user pages List<int> userPagesId = (from up in dcu.GetPages() select up.ID).ToList(); if (userPagesId.Count > 0) dcp.SelectAuthenticatedObjectsFromDb(userPagesId); // list public pages and pages that user can have else dcp.SelectPublicObjectsFromDb(); // -------------------------------- // list pages that user dont have List<JsonUserPages> userPages = (from ap in dcp.AllPages select new JsonUserPages {Id = ap.ID, Title = ap.Title, Name = ap.Name}).ToList(); return js.Serialize(userPages); } catch (Exception ex) { loging.Error("FrontOffice User Webservice", "List All User Pages ", ex.Message, _logRecord); } finally { if (dcp != null) dcp.Close(); } return js.Serialize(""); }
/// <summary> /// Generate header bar /// </summary> private void FillMenuBar(OptionItems foOptions) { string username = "******"; try { headerContainer.Controls.Clear(); UserLoginData user = (UserLoginData)db_config_sessions.GetUserAuthentication(); OptionItems userOi = null; db_config_master_page dcmp = new db_config_master_page(); dcmp.Open(); List<string> userFavorites = new List<string>(); // user not autenticated show just public pages if (user == null) { dcmp.SelectPublicObjectsFromDb(); } else { // user autenticated show public pages and user pages dcmp.SelectAuthenticatedObjectsFromDb(user.UserPages); userOi = new OptionItems(user.User.UserOptions); userFavorites = userOi.GetList("favorites"); // prepare username to be used in error exception. username = user.User.Name; } // set url to use when the page start SelectDefaultPage(foOptions.GetSingle("default_page"), user != null ? userOi.GetSingle("default_frontoffice_page") : ""); MenuBar mb = new MenuBar(); mb.AddHeader("Home", "frontoffice.aspx"); // just show data if is not refresh if (!IsPostBack) { mb.AddHeader("Site pages", ""); // site pages int headerId = mb.GetHeaderPosition("Site pages"); db_config_page dcp; foreach (DbConfig.MasterPage item in dcmp.AllMasterPages) { // just show pages that admin dont want to hide from you :) List<DbConfig.Page> visiblePages = (from p in dcmp.GetAllPages(item.ID) where (new OptionItems(p.Options).GetSingle("hidden_from_frontoffice").Equals("true")) == false select p).ToList(); dcp = new db_config_page(dcmp.Db, visiblePages, item.ID); if (user == null) dcp.SelectPublicObjectsFromDb(); else dcp.SelectAuthenticatedObjectsFromDb(user.UserPages); // will just add master page if it has visible pages to show, // if the master page does not have pages will not get here. if (dcp.AllPages.Count > 0) { // add master page to menu mb.AddMenuItem(headerId, item.Title, ""); int menuItemId = mb.GetMenuPosition(headerId, item.Title); // add pages to sub menus foreach (DbConfig.Page subItem in dcp.AllPages) mb.AddSubMenuItem(headerId, menuItemId, subItem.Title, "page.aspx?nm=" + subItem.Name); } dcp.Close(); } if (userFavorites.Count > 0) // favorites { mb.AddHeader("Favorites", ""); int favItemId = mb.GetHeaderPosition("Favorites"); dcp = new db_config_page(dcmp.Db, new List<DbConfig.Page>(), -1); dcp.Refresh(); foreach (string favpage in userFavorites) { if (!dcp.PageExists(favpage)) continue; DbConfig.Page p = dcp.Get(favpage); mb.AddMenuItem(favItemId, p.Title, "page.aspx?nm=" + p.Name); } dcp.Close(); } } dcmp.Close(); headerContainer.Controls.Add(mb.Get()); Generic.JavaScriptInjector("js", mb.GetLoginJavascript()); } catch (Exception ex) { throw new Exception("error: fill menu bar for user " + username + " - " + ex.Message + " ..."); } }