protected void rtlRolePermissionsForEditing_UpdateCommand(Object source, TreeListCommandEventArgs e) { var editedItem = e.Item as TreeListDataItem; if (editedItem == null) return; Guid newRoleID = new Guid(); Guid.TryParse(lblHeaderItemID.Text, out newRoleID); if (newRoleID == default(Guid)) return; ThinkgateRole role = new ThinkgateRole(newRoleID); if (String.IsNullOrEmpty(role.RoleName)) return; //Get the new values: var newValues = new Hashtable(); e.Item.OwnerTreeList.ExtractValuesFromItem(newValues, editedItem, true); Guid permissionID = new Guid(); Guid.TryParse(newValues["ID"].ToString(), out permissionID); if (permissionID == default(Guid)) return; string permissionName = newValues["Name"] == null ? string.Empty : newValues["Name"].ToString(); int permissionLevel = newValues["PermissionLevelValue"] == null ? 0 : DataIntegrity.ConvertToInt(newValues["PermissionLevelValue"].ToString()); bool hasPermission = newValues["Member"] != null && DataIntegrity.ConvertToBool(newValues["Member"]); ThinkgatePermission permission = new ThinkgatePermission(permissionID); SessionObject sessionObject = (SessionObject)Session["SessionObject"]; ThinkgateUser user = sessionObject.LoggedInUser; if (hasPermission) { permission.PermissionLevel = (ThinkgatePermission.PermissionLevelValues)Enum.ToObject(typeof(ThinkgatePermission.PermissionLevelValues), permissionLevel); //pricingModule.Permissions.Add(permission); // Not sure what point of this was role.UpdateRolePermissions(permissionID, permissionLevel, user.UserName); lblResultMessage.Text = string.Format("Permission {0} was added to Role {1}.", permissionName, role.RoleName); // WSH: Going to loop through the children and deal with them. In theory, you could devise a strategy that involved fewer calls to the DB and did a mass update. However you have to do a uniqueness check on each child insert or do a complete delete of all children recs to then do a mass insert. Since this will be a vary rare update, I decided performance was not important. foreach (TreeListDataItem item in editedItem.ChildItems) { permissionID = new Guid(); Guid.TryParse(item.GetDataKeyValue("ID").ToString(), out permissionID); if (permissionID == default(Guid)) return; role.UpdateRolePermissions(permissionID, permissionLevel, user.UserName); } } else { //pricingModule.Permissions.Remove(permission); // WSH : Not sure what point of this was role.DeleteRolePermissions(permissionID); lblResultMessage.Text = string.Format("Permission {0} was revoked from Role {1}.", permissionName, role.RoleName); // WSH: Going to loop through the children and deal with them. In theory, you could devise a strategy that involved fewer calls to the DB and did a mass update. However you have to do a uniqueness check on each child insert or do a complete delete of all children recs to then do a mass insert. Since this will be a vary rare update, I decided performance was not important. foreach (TreeListDataItem item in editedItem.ChildItems) { permissionID = new Guid(); Guid.TryParse(item.GetDataKeyValue("ID").ToString(), out permissionID); if (permissionID == default(Guid)) return; role.DeleteRolePermissions(permissionID); } } }