protected void GridView2_UserResultCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "ToggleAdminRole") { // Grab the index of the selected row int index = Convert.ToInt32(e.CommandArgument); String selectedUserId = GridView1.DataKeys[index]["UserId"].ToString(); UserContext selectedUser = UserContextDb.GetUserContext(selectedUserId); Debug.WriteLine(selectedUser.UserId + " - " + selectedUser.Role); // Set the inverse of selectedUser.AccountState (ie. Active or Suspended) if (selectedUser.Role == "Admin") { // Remove Admin Role UserContextDb.DeleteUserRole(selectedUser); } else { // Add Admin Role selectedUser.RoleId = "1"; selectedUser.Role = "Admin"; UserContextDb.AddUserRole(selectedUser); } GridView2.DataBind(); } }
protected void UpdateUser_Click(object sender, EventArgs e) { UserContext currentUser = UserContextDb.GetUserContext(User.Identity.GetUserId()); Debug.WriteLine(currentUser.FirstName); Debug.WriteLine("REQUEST: " + txtFirstName.Text); // Override the values of properties that are allowed to be updated UserContext updatedUser = new UserContext(); // updated Fields updatedUser.DisplayName = txtDisplayName.Text; updatedUser.FirstName = txtFirstName.Text; updatedUser.LastName = txtLastName.Text; // Non-changing fields updatedUser.UserId = currentUser.UserId; updatedUser.Email = currentUser.Email; updatedUser.UserName = currentUser.UserName; updatedUser.AccountState = currentUser.AccountState; updatedUser.RoleId = currentUser.RoleId; updatedUser.Role = currentUser.Role; Debug.WriteLine("NEW: " + updatedUser.FirstName); // Store into DB UserContextDb.UpdateUserContext(currentUser, updatedUser); }
protected void GridView1_UserResultCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "ToggleAccountState") { // Grab the index of the selected row int index = Convert.ToInt32(e.CommandArgument); String selectedUserId = GridView1.DataKeys[index]["UserId"].ToString(); UserContext selectedUser = UserContextDb.GetUserContext(selectedUserId); Debug.WriteLine(selectedUser.UserId + " - " + selectedUser.AccountState); // Set the inverse of selectedUser.AccountState (ie. Active or Suspended) selectedUser.AccountState = selectedUser.AccountState == "Active" ? "Suspended" : "Active"; // Toggle the AccountState for the current UserContext AKA user UserContextDb.ToggleUserAccountState(selectedUser); GridView1.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { // Redirect away if not signed in if (string.IsNullOrEmpty(User.Identity.GetUserId())) { Response.StatusCode = 403; Response.Redirect("/Default"); } if (!IsPostBack) { // Grab the UserContext UserContext currentUser = UserContextDb.GetUserContext(User.Identity.GetUserId()); // Fill out the Form txtDisplayName.Text = currentUser.DisplayName; txtEmail.Text = currentUser.Email; txtFirstName.Text = currentUser.FirstName; txtLastName.Text = currentUser.LastName; txtUserName.Text = currentUser.UserName; } }