protected void GetUsers() { using(userConnection db = new userConnection()) { var Users = (from users in db.AspNetUsers select users); UsersGridView.DataSource = Users.ToList(); UsersGridView.DataBind(); } }
protected void SaveButton_Click(object sender, EventArgs e) { string UserID = ""; if(Request.QueryString.Count > 0) { using (userConnection db = new userConnection()) { AspNetUser newUser = new AspNetUser(); UserID = Request.QueryString["Id"].ToString(); newUser = (from users in db.AspNetUsers where users.Id == UserID select users).FirstOrDefault(); newUser.UserName = UserNameTextBox.Text; newUser.PhoneNumber = PhoneNumberTextBox.Text; newUser.Email = EmailTextBox.Text; db.SaveChanges(); Response.Redirect("~/Admin/Users.aspx"); } } if(UserID == "") { // Create a new user store and user manager objects var userStore = new UserStore<IdentityUser>(); var userManager = new UserManager<IdentityUser>(userStore); // Create a new user object var user = new IdentityUser() { UserName = UserNameTextBox.Text, PhoneNumber = PhoneNumberTextBox.Text, Email = EmailTextBox.Text }; //Create a new user in the db and store the result IdentityResult result = userManager.Create(user, PasswordTextBox.Text); if (result.Succeeded) { Response.Redirect("~/Admin/Users.aspx"); } else { StatusLabel.Text = result.Errors.FirstOrDefault(); AlertFlash.Visible = true; } } }
protected void GetUser() { string UserID = Request.QueryString["Id"].ToString(); using(userConnection db = new userConnection()) { AspNetUser updatedUser = (from user in db.AspNetUsers where user.Id == UserID select user).FirstOrDefault(); if(updatedUser != null) { UserNameTextBox.Text = updatedUser.UserName; PhoneNumberTextBox.Text = updatedUser.PhoneNumber; EmailTextBox.Text = updatedUser.Email; } } }
protected void UsersGridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { int selectedRow = e.RowIndex; string UserID = UsersGridView.DataKeys[selectedRow].Values["Id"].ToString(); using(userConnection db = new userConnection()) { AspNetUser deletedUser = (from users in db.AspNetUsers where users.Id == UserID select users).FirstOrDefault(); db.AspNetUsers.Remove(deletedUser); db.SaveChanges(); this.GetUsers(); } }