protected void Add_Click(object sender, EventArgs e) { var userStore = new UserStore <IdentityUser>(); var manager = new UserManager <IdentityUser>(userStore); string email = Email.Text; string pass = RandomString(12); var user = new IdentityUser() { UserName = email, Email = email }; IdentityResult result = manager.Create(user, pass); //send to email with new pass if (result.Succeeded) { string HtmlBody = GeneralFunctions.CreateEmailBody(repo.SuccessRegisterEmailBodyPath, email, pass); GeneralFunctions.SendEmail(repo.EmailFrom, email, repo.EmailFrom, repo.EmailSubject, repo.EmailHost, repo.EmailPort, repo.SMTPUserName, repo.SMTPPassword, HtmlBody); UsersGV.DataSource = usersBLL.getAllUsers(); UsersGV.DataBind(); Response.Redirect(Request.RawUrl); } else { lblModal.Text = result.Errors.FirstOrDefault(); ScriptManager.RegisterStartupScript(this, this.GetType(), "myModal", "$('#divPopUp').modal('show');", true); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (User.Identity.IsAuthenticated && User.IsInRole("Superusers")) { } else { Response.Redirect("/UI/Login.aspx"); } UsersGV.DataSource = settingsBLL.getAllSettings(); UsersGV.DataBind(); } }
protected void Delete_Click(object sender, EventArgs e) { //Get the button that raised the event Button btn = (Button)sender; //Get the row that contains this button GridViewRow gvr = (GridViewRow)btn.NamingContainer; string id = gvr.Cells[0].Text; var userStore = new UserStore <IdentityUser>(); var userManager = new UserManager <IdentityUser>(userStore); var user = userManager.FindById(id); if (user != null) { var oldSettings = settingsBLL.getSettingsByUserId(id); if (oldSettings != null) { oldSettings.UserId = null; var oldResult = settingsBLL.update(oldSettings); if (oldResult == null) { lblModal.Text = "Failed to update"; ScriptManager.RegisterStartupScript(this, this.GetType(), "myModal", "$('#divPopUp').modal('show');", true); return; } } userStore.DeleteAsync(user); UsersGV.DataSource = usersBLL.getAllUsers(); UsersGV.DataBind(); Response.Redirect(Request.RawUrl); } else { lblModal.Text = "Failed to delete account"; ScriptManager.RegisterStartupScript(this, this.GetType(), "myModal", "$('#divPopUp').modal('show');", true); } }
protected void UsersGV_PageIndexChanging(object sender, GridViewPageEventArgs e) { UsersGV.PageIndex = e.NewPageIndex; UsersGV.DataBind(); }