protected void UpdateUserButton_Click(object sender, EventArgs e) { try { // Create new user. clsESPSql.ExecNonQuery("update aspnet_Users set mobilealias='" + Mobile.Text + "' where username='******'"); try { LIBtblmstOrgUsers objLIBtblmstOrgUsers = new LIBtblmstOrgUsers(); DALtblmstOrgUsers objDALtblmstOrgUsers = new DALtblmstOrgUsers(); MyCLS.TransportationPacket tp = new MyCLS.TransportationPacket(); objLIBtblmstOrgUsers.id = -1; objLIBtblmstOrgUsers.Name = Name.Text; objLIBtblmstOrgUsers.Email = Email.Text; objLIBtblmstOrgUsers.Phone = Mobile.Text; objLIBtblmstOrgUsers.orgid = Convert.ToInt32(Session["orgid"].ToString()); tp.MessagePacket = objLIBtblmstOrgUsers; tp = objDALtblmstOrgUsers.InserttblmstOrgUsers(tp); } catch (Exception ex) { MyCLS.clsHandleException.HandleEx(ex, System.Reflection.MethodBase.GetCurrentMethod().ToString(), true); } // Response.Redirect("user.aspx", false); UserName.Text = ""; Email.Text = ""; Mobile.Text = ""; UserType.SelectedIndex = 0; lblErrorMessage.Text = "user details updated successfully"; lblErrorMessage.ForeColor = System.Drawing.Color.Green; UserType.Enabled = true; CreateUserButton.Visible = true; UpdateUser.Visible = false; DataTable dt = clsESPSql.ExecQuery("SP_GetUserByRole 'DataEntry' "); rptuserlist.DataSource = dt; rptuserlist.DataBind(); ViewState["dt"] = dt; } catch (MembershipCreateUserException ex) { //lblErrorMessage.Text = GetErrorMessage(ex.StatusCode); } }
protected void CreateUserButton_Click(object sender, EventArgs e) { try { // Create new user. MembershipCreateStatus status; Password.Text = GeneratePWD(); MembershipUser newUser = Membership.CreateUser(Email.Text, Password.Text, Email.Text, null, null, true, out status); //if (!Roles.IsUserInRole("Manager")) //{ string role = UserType.SelectedValue; if (!Roles.RoleExists(role)) { Roles.CreateRole(role); Roles.AddUserToRole(Email.Text, role); } else { //Roles.RemoveUserFromRole(Email.Text, role); Roles.AddUserToRole(Email.Text, role); } clsESPSql.ExecNonQuery("update aspnet_Users set pwd='" + Password.Text + "', mobilealias='" + Mobile.Text + "' where username='******'"); try { LIBtblmstOrgUsers objLIBtblmstOrgUsers = new LIBtblmstOrgUsers(); DALtblmstOrgUsers objDALtblmstOrgUsers = new DALtblmstOrgUsers(); MyCLS.TransportationPacket tp = new MyCLS.TransportationPacket(); objLIBtblmstOrgUsers.id = -1; objLIBtblmstOrgUsers.Name = Name.Text; objLIBtblmstOrgUsers.Email = Email.Text; objLIBtblmstOrgUsers.Phone = Mobile.Text; objLIBtblmstOrgUsers.orgid = Convert.ToInt32(Session["orgid"].ToString()); tp.MessagePacket = objLIBtblmstOrgUsers; tp = objDALtblmstOrgUsers.InserttblmstOrgUsers(tp); DataTable dt = clsESPSql.ExecQuery("SP_GetUserByRole 'DataEntry', " + Session["orgid"].ToString()); rptuserlist.DataSource = dt; rptuserlist.DataBind(); ViewState["dt"] = dt; } catch (Exception ex) { MyCLS.clsHandleException.HandleEx(ex, System.Reflection.MethodBase.GetCurrentMethod().ToString(), true); } DALCommon cmn = new DALCommon(); string strBody = cmn.prcFindInFile(Server.MapPath("mail.html").ToString(), "#UserName#", Email.Text); strBody = cmn.prcFindInString(strBody, "#Password#", Password.Text); cmn.SendHtmlFormattedEmail(Email.Text, "Account Created", strBody); // Response.Redirect("user.aspx", false); UserName.Text = ""; Email.Text = ""; Mobile.Text = ""; UserType.SelectedIndex = 0; lblErrorMessage.Text = "User Created successfully"; lblErrorMessage.ForeColor = System.Drawing.Color.Green; } catch (MembershipCreateUserException ex) { lblErrorMessage.Text = GetErrorMessage(ex.StatusCode); } }