protected void btnSaveUser_Click(object sender, EventArgs e) { int iUserID = 0; int.TryParse(Request["UserID"], out iUserID); if (User.IsInRole("editor")) iUserID = Blogsa.ActiveUser.UserID; BSUser user = BSUser.GetUser(iUserID); if (user == null) { user = new BSUser(); user.UserName = txtUserName.Text; user.Password = BSHelper.GetMd5Hash(txtPassword.Text); } else if (!String.IsNullOrEmpty(txtPassword.Text)) user.Password = BSHelper.GetMd5Hash(txtPassword.Text); if (Blogsa.ActiveUser.Role.Equals("admin")) user.Role = rblRole.SelectedValue; else user.Role = "user"; user.UserName = txtUserName.Text; user.Name = txtName.Text; user.Email = txtEmail.Text; user.WebPage = txtWebPage.Text; if (user.UserID != 1) user.Role = rblRole.SelectedValue; if (user.Save()) { MessageBox1.Message = Language.Admin["UserSaved"]; MessageBox1.Type = MessageBox.ShowType.Information; } else { MessageBox1.Message = "Error"; MessageBox1.Type = MessageBox.ShowType.Error; } }
private void SaveAllData() { XmlRootAttribute root = new XmlRootAttribute(); root.ElementName = "Data"; root.IsNullable = true; XmlSerializer dataSerializer = new XmlSerializer(typeof(BSData), root); using (TextReader reader = new StreamReader(Server.MapPath(String.Format("~/Setup/Data/{0}.xml", Session["lang"])))) { BSData data = (BSData)dataSerializer.Deserialize(reader); if (data != null) { if (data.Sites != null) { foreach (BSSite bsSite in data.Sites) { bsSite.Save(); } } if (data.Settings != null) { foreach (BSSetting bsSetting in data.Settings) { bsSetting.Save(); } } if (data.Posts != null) { foreach (BSPost bsPost in data.Posts) { bsPost.Save(); } } if (data.MenuGroups != null) { foreach (BSMenuGroup bsMenuGroup in data.MenuGroups) { bsMenuGroup.Save(); } } if (data.Menus != null) { foreach (BSMenu bsMenu in data.Menus) { bsMenu.Save(); } } if (data.Users != null) { foreach (BSUser bsUser in data.Users) { bsUser.Save(); } } if (data.Widgets != null) { foreach (BSWidget bsWidget in data.Widgets) { bsWidget.Save(); } } if (data.Links != null) { foreach (BSLink bsLink in data.Links) { bsLink.Save(); } } if (data.Terms != null) { foreach (BSTerm bsTerm in data.Terms) { bsTerm.Save(); } } Blogsa.Settings = null; } } if (Session["Password"] == null) { string password = BSHelper.GetRandomStr(8); BSUser user = BSUser.GetUserByUserName("admin"); user.Password = BSHelper.GetMd5Hash(password); user.Save(); Session["Password"] = password; } Session["Step"] = "Finish"; Response.Redirect("Completed.aspx"); }
private static void FillUser(IDataReader dr, BSUser user) { user.UserID = Convert.ToInt32(dr["UserID"]); user.Email = dr["Email"].ToString(); user.LastLoginDate = dr["LastLoginDate"] == DBNull.Value ? Convert.ToDateTime(dr["CreateDate"]) : Convert.ToDateTime(dr["LastLoginDate"]); user.WebPage = dr["WebPage"].ToString(); user.Name = dr["Name"].ToString(); user.UserName = dr["UserName"].ToString(); user.Role = dr["Role"].ToString(); user.State = Convert.ToInt16(dr["State"]); user.Password = dr["Password"].ToString(); user.CreateDate = Convert.ToDateTime(dr["CreateDate"]); }
protected void gvUsers_DataBinding(object sender, EventArgs e) { ((GridView)sender).DataSource = BSUser.GetUsers(); }
public static void OnSaved(BSUser user, EventArgs e) { if (Saved != null) { Saved(user, e); } }
public static void OnSaving(BSUser user, CancelEventArgs e) { if (Saving != null) { Saving(user, e); } }
public static void OnDeleting(BSUser user, CancelEventArgs e) { if (Deleting != null) { Deleting(user, e); } }
public static void OnDeleted(BSUser user, EventArgs e) { if (Deleted != null) { Deleted(user, e); } }
public static List<BSUser> GetUsers() { List<BSUser> users = new List<BSUser>(); using (DataProcess dp = new DataProcess()) { dp.ExecuteReader("SELECT * FROM Users"); if (dp.Return.Status == DataProcessState.Success) { using (IDataReader dr = dp.Return.Value as IDataReader) { while (dr != null && dr.Read()) { BSUser user = new BSUser(); FillUser(dr, user); users.Add(user); } } } } return users; }
public static BSUser GetUserByUserName(string userName) { using (DataProcess dp = new DataProcess()) { dp.AddParameter("UserName", userName); dp.ExecuteReader("SELECT * FROM Users WHERE [UserName]=@UserName"); if (dp.Return.Status == DataProcessState.Success) { using (IDataReader dr = dp.Return.Value as IDataReader) { if (dr != null && dr.Read()) { BSUser user = new BSUser(); FillUser(dr, user); return user; } } } } return null; }
public static int GetPostCountForUserID(int iUserId) { return(BSUser.GetUser(iUserId).GetPosts().Count); }