private void SaveData() { // Remove old items string newValues = ValidationHelper.GetString(usRoles.Value, null); string items = DataHelper.GetNewItemsInList(newValues, currentValues); if (!String.IsNullOrEmpty(items)) { string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { // Add all new items to site foreach (string item in newItems) { int roleID = ValidationHelper.GetInteger(item, 0); // If role is authorized, unauthorize it if (IsRoleAuthorized(roleID.ToString(), workflowStepId)) { WorkflowStepRoleInfoProvider.RemoveRoleFromWorkflowStep(workflowStepId, roleID); } } } } // Add new items items = DataHelper.GetNewItemsInList(currentValues, newValues); if (!String.IsNullOrEmpty(items)) { string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { // Add all new items to site foreach (string item in newItems) { int roleID = ValidationHelper.GetInteger(item, 0); // If role is not authorized, authorize it if (!IsRoleAuthorized(roleID.ToString(), workflowStepId)) { WorkflowStepRoleInfoProvider.AddRoleToWorkflowStep(workflowStepId, roleID); } } } } lblInfo.Visible = true; lblInfo.Text = GetString("General.ChangesSaved"); }
/// <summary> /// Removes the assignment of the CMS Editors role from a workflow step. Called when the "Remove role from step" button is pressed. /// Expects the CreateWorkflow, CreateWorkflowStep and AddRoleToStep methods to be run first. /// </summary> private bool RemoveRoleFromStep() { // Get the workflow WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow", WorkflowTypeEnum.Approval); if (workflow != null) { // Get the custom step WorkflowStepInfo step = WorkflowStepInfoProvider.GetWorkflowStepInfo("MyNewWorkflowStep", workflow.WorkflowID); if (step != null) { // Get the role to be assigned to the step RoleInfo role = RoleInfoProvider.GetRoleInfo("CMSEditor", SiteContext.CurrentSiteID); if (role != null) { // Get the step - role relationship WorkflowStepRoleInfo stepRoleInfo = WorkflowStepRoleInfoProvider.GetWorkflowStepRoleInfo(step.StepID, role.RoleID); if (stepRoleInfo != null) { // Remove the assignment WorkflowStepRoleInfoProvider.RemoveRoleFromWorkflowStep(step.StepID, role.RoleID); return(true); } else { // The role is not assigned to the step apiRemoveRoleFromStep.ErrorMessage = "The 'CMS Editors' role is not assigned to the step."; } } else { // The role was not found apiRemoveRoleFromStep.ErrorMessage = "The role 'CMS Editors' was not found."; } } else { // The step was not found apiRemoveRoleFromStep.ErrorMessage = "The step 'My new workflow step' was not found."; } } return(false); }