public string GetUserFavorites(string userId, string ctrl) { JavaScriptSerializer js = new JavaScriptSerializer(); string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey")); //if (ctrl != crlHash) return js.Serialize(""); db_config_users dcu = null; 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(""); dcu = new db_config_users(auxUserId); dcu.Open(); dcp = new db_config_page(); dcp.Open(); object userOptions = dcu.Get(auxUserId).UserOptions; if (userOptions == null) return js.Serialize(""); OptionItems oi = new OptionItems((string)userOptions); List<Dictionary<string, string>> favoriteList = new List<Dictionary<string, string>>(); foreach (string favoritePage in oi.GetList("favorites")) { try { string title = dcp.Get(favoritePage).Title; favoriteList.Add(new Dictionary<string, string>() { {"Name", favoritePage}, {"Title", title} }); } catch {} } return js.Serialize(favoriteList); } catch (Exception ex) { loging.Error("FrontOffice User Webservice", "Get Favorites ", ex.Message, _logRecord); } finally { if (dcu != null) dcu.Close(); try { if(dcp != null) dcp.Close(); } catch {} // needed to open a new connection (forgot to implement a page method that accepts new ) } return js.Serialize(""); }
public string GetUserDefaultPage(string userId, string ctrl) { JavaScriptSerializer js = new JavaScriptSerializer(); string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey")); //if (ctrl != crlHash) return js.Serialize(""); db_config_users dcu = null; // user db_config_page dcp = null; // page try { // first validation to guarantee that user is greater than zero int auxUserId = Convert.ToInt32(userId); if (auxUserId < 0) return js.Serialize(""); dcu = new db_config_users(auxUserId); dcu.Open(); object userOptions = dcu.Get(auxUserId).UserOptions; // if user does not exist leaves if (userOptions == null) return string.Empty; OptionItems oi = new OptionItems((string)userOptions); string pageName = oi.GetSingle("default_frontoffice_page"); // if no default page leave if (pageName == string.Empty) return string.Empty; dcp = new db_config_page(pageName); dcp.Open(); string pageTitle = dcp.Get(pageName).Title; Dictionary<string, string> defPage = new Dictionary<string, string>() {{"Name", pageName}, {"Title", pageTitle}}; return js.Serialize(defPage); } catch (Exception ex) { loging.Error("FrontOffice User Webservice", "Get Default Page ", ex.Message, _logRecord); } finally { if (dcu != null) dcu.Close(); try { if(dcp != null) dcp.Close(); } catch { } } return string.Empty; }
public string AddUserFavoritePage(string userId, string pageName, string ctrl) { string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey")); //if (ctrl != crlHash) return js.Serialize(""); db_config_users dcu = null; try { // first validation to guarantee that user is greater than zero int auxUserId = Convert.ToInt32(userId); if (auxUserId < 0) return string.Empty; dcu = new db_config_users(auxUserId); dcu.Open(); Users u = dcu.Get(auxUserId); if (u == null) return string.Empty; // if user does not exists will leave width no return message OptionItems oi = new OptionItems(u.UserOptions); List<string> favoriteList = oi.GetList("favorites"); if (favoriteList.IndexOf(pageName) < 0) { favoriteList.Add(pageName); oi.UpdateOptions("favorites", favoriteList); u.UserOptions = oi.GetOptionsString(); dcu.Commit(); return "page added to favorites"; } else return "page already added to favorite."; } catch (Exception ex) { loging.Error("FrontOffice User Webservice", "Add User Favorite Page", ex.Message, _logRecord); } finally { if (dcu != null) dcu.Close(); } return "failed to add page"; }
public string SetUserDefaultFrontOfficePage(string userId, string pageName, string ctrl) { string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey")); //if (ctrl != crlHash) return js.Serialize(""); db_config_users dcu = null; try { // first validation to guarantee that user is greater than zero int auxUserId = Convert.ToInt32(userId); if (auxUserId < 0) return string.Empty; dcu = new db_config_users(auxUserId); dcu.Open(); Users u = dcu.Get(auxUserId); if (u == null) return string.Empty; // if user does not exists it will leave with no return messsage OptionItems oi = new OptionItems(u.UserOptions); oi.UpdateOptions("default_frontoffice_page", new List<string> { pageName }); u.UserOptions = oi.GetOptionsString(); dcu.Commit(); return pageName != "" ? "Page " + pageName + " is set as default frontoffice page" : "Default frontoffice page is clean"; } catch (Exception ex) { loging.Error("FrontOffice User Webservice", "Add User Favorite Page", ex.Message, _logRecord); } finally { if (dcu != null) dcu.Close(); } return "failed to set page"; }
public string ChangeUserPassword(string userId, string newPass, string ctrl) { JavaScriptSerializer js = new JavaScriptSerializer(); string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey")); //if (ctrl != crlHash) return js.Serialize(""); db_config_users dcu = null; try { // first validation to guarantee that user is greater than zero int auxUserId = Convert.ToInt32(userId); if (auxUserId < 0) return js.Serialize(""); dcu = new db_config_users(auxUserId); dcu.Open(); Users u = dcu.Get(auxUserId); if (u == null) return string.Empty; // if user does not exists it will leave with no return messsage u.Pass = newPass; dcu.Commit(); return "password changed"; } catch (Exception ex) { loging.Error("FrontOffice User Webservice", "User Change Password", ex.Message, _logRecord); } finally { if (dcu != null) dcu.Close(); } return "password not changed"; }
/************************ Configurations ************************/ /// <summary> /// updating existing user data /// </summary> private static void SaveUser(string uId, string name, string pass, int admin, string desc, string uOptions, string aOptions) { try { int id = Convert.ToInt32(uId); db_config_users dcu = new db_config_users(id); dcu.Open(); // open connection Users user = dcu.Get(id); if (user.ID != id) return; // if id is diferent probabaly because user pressed save with no user selected user.Name = name; user.Pass = pass; user.AdMIn = admin; user.Description = desc; user.UserOptions = uOptions; user.AdMInOptions = aOptions; dcu.Commit(); dcu.Close(); // close connection Generic.JavaScriptInjector("alert('User Saved'); window.location.reload();"); } catch (Exception ex) { Generic.JavaScriptInjector("alert('" + ex.Message + "');"); } }