protected void DeleteButton_Click(object sender, EventArgs e) { try { string roleName = ViewState["RoleName"].ToString(); if (roleName == "") { return; } string[] userNames = Roles.GetUsersInRole(roleName); if (userNames.Length > 0) { return; } //Roles.RemoveUsersFromRole(userNames, roleName); Roles.DeleteRole(roleName); RolePermissions roleController = new RolePermissions(); List <RolePermissions> list = roleController.GetByRolePermissionName(roleName); if (list != null) { for (int i = 0; i < list.Count; i++) { RolePermissions role = list[i]; roleController.Delete(role.RolePermissionID); } } //WebHelper.LogAction("dbo.RolePermissions", ViewState["RoleName"].ToString(), ActionLog.LogAction.Delete); this.Redirect(); } catch (Exception ex) { } }
private void SavePermissions(string roleName) { RolePermissions roleController = new RolePermissions(); List <RolePermissions> list = roleController.GetByRolePermissionName(roleName); if (list != null) { for (int i = 0; i < list.Count; i++) { RolePermissions role = list[i]; roleController.Delete(role.RolePermissionID); } list.Clear(); } else { list = new List <RolePermissions>(); } foreach (GridViewRow row in permissionGridView.Rows) { CheckBox accessableCheckBox = (CheckBox)row.FindControl("accessableCheckBox"); if (accessableCheckBox == null || !accessableCheckBox.Checked) { continue; } RolePermissions item = new RolePermissions(); item.RoleName = roleName; item.PageName = row.Cells[0].Text; item.Accessable = accessableCheckBox.Checked; list.Add(item); roleController.Add(item); } UpdateAllowedPagesInSession(list, roleName); }