| Sub btnCreateRole_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim roleName As String = txtCreateRole.Text Try Roles.CreateRole(roleName) lblResults.Text = Nothing lblResults.Visible = False txtCreateRole.Text = Nothing Catch ex As Exception lblResults.Text = "Could not create the role: " + Server.HtmlEncode(ex.Message) lblResults.Visible = True End Try End Sub Sub btnDeleteRole_Click(ByVal sender As Object, ByVal e As System.EventArgs) If (lbxAvailableRoles.SelectedIndex <> -1) Then Try Roles.DeleteRole(lbxAvailableRoles.SelectedValue) lblResults.Text = Nothing lblResults.Visible = False Catch ex As Exception lblResults.Text = "Could not delete the role: " + Server.HtmlEncode(ex.Message) lblResults.Visible = True End Try End If End Sub |
| Sub btnAddUserToRole_Click(ByVal sender As Object, ByVal e As System.EventArgs) If (lbxAvailableRoles.SelectedIndex <> -1) Then Dim selectedRole As String = lbxAvailableRoles.SelectedValue If Not Roles.IsUserInRole(selectedRole) Then Try Roles.AddUserToRole(User.Identity.Name, selectedRole) RefreshCurrentRolesListBox() Catch ex As Exception lblResults.Text = "Could not add the user to the role: " + Server.HtmlEncode(ex.Message) lblResults.Visible = True End Try Else lbxAvailableRoles.SelectedIndex = -1 End If End If End Sub Sub btnDeleteUserFromRole_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim selectedRole As String = lbxUserRoles.SelectedValue If (lbxUserRoles.SelectedIndex <> -1) Then Try Roles.RemoveUserFromRole(User.Identity.Name, selectedRole) RefreshCurrentRolesListBox() Catch ex As Exception lblResults.Text = "Could not remove the user from the role: " + Server.HtmlEncode(ex.Message) lblResults.Visible = True End Try End If End Sub |