protected DataTable ConvertToPricingModulePermissionsBindingTable(ThinkgatePermissionsCollection permissions, ThinkgatePricingModule pricingModule) { DataTable table = new DataTable(); table.Columns.Add(new DataColumn("ID", typeof(System.Guid))); table.Columns.Add(new DataColumn("ParentID", typeof(System.Guid))); table.Columns.Add(new DataColumn("Name", typeof(string))); table.Columns.Add(new DataColumn("Member", typeof(bool))); table.Columns.Add(new DataColumn("PermissionLevelValue", typeof(int))); table.Columns.Add(new DataColumn("Description", typeof(string))); foreach (ThinkgatePermission permission in permissions) { DataRow row = table.NewRow(); row["ID"] = permission.PermissionId; row["ParentID"] = permission.ParentPermissionId; row["Name"] = permission.PermissionName; row["Member"] = pricingModule.Permissions.Contains(permission); row["PermissionLevelValue"] = pricingModule.Permissions.Contains(permission) ? pricingModule.Permissions.GetPermission(permission.PermissionId).PermissionLevelValue : DataIntegrity.ConvertToInt(ThinkgatePermission.PermissionLevelValues.NoValue.ToString()); row["Description"] = permission.Description; table.Rows.Add(row); } return table; }
protected void rgSchoolPricingModulesForEditing_UpdateCommand(Object source, GridCommandEventArgs e) { var editedItem = e.Item as GridEditableItem; if (editedItem == null) return; int newSchoolID = DataIntegrity.ConvertToInt(lblHeaderItemID.Text); if (newSchoolID == default(int)) return; ThinkgateSchool school = new ThinkgateSchool(newSchoolID, true); if (String.IsNullOrEmpty(school.Name)) return; //Get the new values: var newValues = new Hashtable(); e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem); int pricingModuleID = DataIntegrity.ConvertToInt(editedItem.GetDataKeyValue("ID").ToString()); if (pricingModuleID == default(int)) return; bool hasPermission = newValues["Member"] != null && DataIntegrity.ConvertToBool(newValues["Member"]); ThinkgatePricingModule pricingModule = new ThinkgatePricingModule(pricingModuleID); if (hasPermission) { school.PricingModules.Add(pricingModule); SessionObject sessionObject = (SessionObject)Session["SessionObject"]; ThinkgateUser user = sessionObject.LoggedInUser; school.UpdateSchoolPricingModules(pricingModuleID, user.UserName); lblResultMessage.Text = string.Format("Pricing Module {0} was added to School {1}.", pricingModule.Name, school.Name); } else { school.PricingModules.Remove(pricingModule); school.DeleteSchoolPricingModules(pricingModuleID); lblResultMessage.Text = string.Format("Pricing Module {0} was revoked from School {1}.", pricingModule.Name, school.Name); } }
protected void rtlPricingModulePermissionsForEditing_UpdateCommand(Object source, TreeListCommandEventArgs e) { var editedItem = e.Item as TreeListDataItem; if (editedItem == null) return; int newPricingModuleID = DataIntegrity.ConvertToInt(lblHeaderItemID.Text); if (newPricingModuleID == default(int)) return; ThinkgatePricingModule pricingModule = new ThinkgatePricingModule(newPricingModuleID); if (String.IsNullOrEmpty(pricingModule.Name)) 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(); bool hasPermission = newValues["Member"] != null && DataIntegrity.ConvertToBool(newValues["Member"]); //ThinkgatePermission permission = new ThinkgatePermission(permissionID); // WSH : Not sure what point of this was SessionObject sessionObject = (SessionObject)Session["SessionObject"]; ThinkgateUser user = sessionObject.LoggedInUser; if (hasPermission) { //pricingModule.Permissions.Add(permission); // Not sure what point of this was pricingModule.UpdatePricingModulePermissions(permissionID, 0, user.UserName); lblResultMessage.Text = string.Format("Permission {0} was added to Pricing Module {1}.", permissionName, pricingModule.Name); // 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; pricingModule.UpdatePricingModulePermissions(permissionID, 0, user.UserName); } } else { //pricingModule.Permissions.Remove(permission); // WSH : Not sure what point of this was pricingModule.DeletePricingModulePermissions(permissionID); lblResultMessage.Text = string.Format("Permission {0} was revoked from Pricing Module {1}.", permissionName, pricingModule.Name); // 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; pricingModule.DeletePricingModulePermissions(permissionID); } } }
protected void rtlPricingModulePermissionsForEditing_NeedDataSource(object sender, TreeListNeedDataSourceEventArgs e) { int pricingModuleID = DataIntegrity.ConvertToInt(Request.QueryString["ID"]); if (pricingModuleID == 0) return; ThinkgatePermissionsCollection permissions = new ThinkgatePermissionsCollection(); permissions.GetPermissionsCollection(PermissionCollectionTypes.All, 1); ThinkgatePricingModule pricingModule = new ThinkgatePricingModule(pricingModuleID); lblHeaderItemID.Text = pricingModule.Id.ToString(); lblHeaderItemName.Text = String.Format("Permissions in {0} Pricing Module:", pricingModule.Name); rtlPricingModulePermissionsForEditing.DataSource = ConvertToPricingModulePermissionsBindingTable(permissions, pricingModule); }
protected void rgPricingModules_UpdateCommand(Object source, GridCommandEventArgs e) { var editedItem = e.Item as GridEditableItem; if (editedItem == null) return; //Get the new values: var newValues = new Hashtable(); e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem); int id = DataIntegrity.ConvertToInt(editedItem.GetDataKeyValue("ID").ToString()); string name = newValues["Name"] == null ? string.Empty : newValues["Name"].ToString(); bool active = newValues["Active"] != null && DataIntegrity.ConvertToBool(newValues["Active"]); if (id < 1) return; ThinkgatePricingModule pricingModule = new ThinkgatePricingModule(id, name, active); pricingModule.UpdatePricingModule(); LoadPricingModules(); }