/// <summary> /// Gets the edit value as the IEntity.Id /// </summary> /// <param name="control">The control.</param> /// <param name="configurationValues">The configuration values.</param> /// <returns></returns> public int?GetEditValueAsEntityId(Control control, Dictionary <string, ConfigurationValue> configurationValues) { Guid guid = GetEditValue(control, configurationValues).AsGuid(); var item = new WorkflowTypeService(new RockContext()).Get(guid); return(item != null ? item.Id : (int?)null); }
/// <summary> /// Execute method to write transaction to the database. /// </summary> public void Execute() { if ( Trigger != null ) { var rockContext = new RockContext(); var workflowTypeService = new WorkflowTypeService( rockContext ); var workflowType = workflowTypeService.Get( Trigger.WorkflowTypeId ); if ( workflowType != null ) { var workflow = Rock.Model.Workflow.Activate( workflowType, Trigger.WorkflowName ); List<string> workflowErrors; if ( workflow.Process( rockContext, Entity, out workflowErrors ) ) { if ( workflow.IsPersisted || workflowType.IsPersisted ) { var workflowService = new Rock.Model.WorkflowService( rockContext ); workflowService.Add( workflow ); rockContext.WrapTransaction( () => { rockContext.SaveChanges(); workflow.SaveAttributeValues( rockContext ); foreach ( var activity in workflow.Activities ) { activity.SaveAttributeValues( rockContext ); } } ); } } } } }
/// <summary> /// Launch the workflow /// </summary> protected void LaunchTheWorkflow(string workflowName) { Guid workflowTypeGuid = Guid.NewGuid(); if (Guid.TryParse(workflowName, out workflowTypeGuid)) { var workflowTypeService = new WorkflowTypeService(); var workflowType = workflowTypeService.Get(workflowTypeGuid); if (workflowType != null) { var workflow = Rock.Model.Workflow.Activate(workflowType, workflowName); List <string> workflowErrors; if (workflow.Process(out workflowErrors)) { if (workflowType.IsPersisted) { var workflowService = new Rock.Model.WorkflowService(); workflowService.Add(workflow, CurrentPersonId); workflowService.Save(workflow, CurrentPersonId); } } } } }
public Rock.Model.Workflow WorkflowEntry( int workflowTypeId ) { var rockContext = new Rock.Data.RockContext(); var workflowTypeService = new WorkflowTypeService( rockContext ); var workflowType = workflowTypeService.Get( workflowTypeId ); if ( workflowType != null ) { var workflow = Rock.Model.Workflow.Activate( workflowType, "Workflow From REST" ); // set workflow attributes from querystring foreach(var parm in Request.GetQueryStrings()){ workflow.SetAttributeValue( parm.Key, parm.Value ); } // save -> run workflow List<string> workflowErrors; new Rock.Model.WorkflowService( rockContext ).Process( workflow, out workflowErrors ); var response = ControllerContext.Request.CreateResponse( HttpStatusCode.Created ); return workflow; } else { var response = ControllerContext.Request.CreateResponse( HttpStatusCode.NotFound ); } return null; }
public Rock.Model.Workflow WorkflowEntry(int workflowTypeId) { var rockContext = new Rock.Data.RockContext(); var workflowTypeService = new WorkflowTypeService(rockContext); var workflowType = workflowTypeService.Get(workflowTypeId); if (workflowType != null) { var workflow = Rock.Model.Workflow.Activate(workflowType, "Workflow From REST"); // set workflow attributes from querystring foreach (var parm in Request.GetQueryStrings()) { workflow.SetAttributeValue(parm.Key, parm.Value); } // save -> run workflow List <string> workflowErrors; new Rock.Model.WorkflowService(rockContext).Process(workflow, out workflowErrors); var response = ControllerContext.Request.CreateResponse(HttpStatusCode.Created); return(workflow); } else { var response = ControllerContext.Request.CreateResponse(HttpStatusCode.NotFound); } return(null); }
/// <summary> /// Handles the Click event of the btnEdit control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnEdit_Click(object sender, EventArgs e) { WorkflowTypeService service = new WorkflowTypeService(); WorkflowType item = service.Get(int.Parse(hfWorkflowTypeId.Value)); ShowEditDetails(item); }
/// <summary> /// Sets the value. ( as Guid ) /// </summary> /// <param name="control">The control.</param> /// <param name="configurationValues"></param> /// <param name="value">The value.</param> public override void SetEditValue(Control control, Dictionary <string, ConfigurationValue> configurationValues, string value) { if (value != null) { var picker = control as WorkflowTypePicker; if (picker != null) { var guids = new List <Guid>(); foreach (string guidValue in value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { Guid?guid = guidValue.AsGuidOrNull(); if (guid.HasValue) { guids.Add(guid.Value); } } if (guids.Any()) { var workflowTypes = new WorkflowTypeService(new RockContext()).Queryable().Where(a => guids.Contains(a.Guid)).ToList(); picker.SetValues(workflowTypes); } } } }
/// <summary> /// Creates the HTML controls required to configure this type of field /// </summary> /// <returns></returns> public override List <Control> ConfigurationControls() { var controls = base.ConfigurationControls(); // build a drop down list of defined types (the one that gets selected is // used to build a list of defined values) var ddl = new RockDropDownList(); controls.Add(ddl); ddl.AutoPostBack = true; ddl.SelectedIndexChanged += OnQualifierUpdated; ddl.Label = "Workflow Type"; ddl.Help = "Workflow Type to select workflows from, if left blank any workflow type's workflows can be selected."; ddl.Items.Add(new ListItem()); var workflowTypeService = new WorkflowTypeService(new RockContext()); var workflowTypes = workflowTypeService.Queryable().OrderBy(a => a.Name).ToList(); workflowTypes.ForEach(g => ddl.Items.Add(new ListItem(g.Name, g.Id.ToString().ToUpper())) ); return(controls); }
/// <summary> /// Returns the field's current value(s) /// </summary> /// <param name="parentControl">The parent control.</param> /// <param name="value">Information about the value</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param> /// <returns></returns> public override string FormatValue( Control parentControl, string value, Dictionary<string, ConfigurationValue> configurationValues, bool condensed ) { string formattedValue = string.Empty; if ( !string.IsNullOrWhiteSpace( value ) ) { var names = new List<string>(); var guids = new List<Guid>(); foreach ( string guidValue in value.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ) ) { Guid? guid = guidValue.AsGuidOrNull(); if ( guid.HasValue ) { guids.Add( guid.Value ); } } if ( guids.Any() ) { var workflowTypes = new WorkflowTypeService( new RockContext() ).Queryable().Where( a => guids.Contains( a.Guid ) ); if ( workflowTypes.Any() ) { formattedValue = string.Join( ", ", ( from workflowType in workflowTypes select workflowType.Name ).ToArray() ); } } } return base.FormatValue( parentControl, formattedValue, null, condensed ); }
/// <summary> /// Launch the workflow /// </summary> protected void LaunchTheWorkflow(string workflowName) { Guid workflowTypeGuid = Guid.NewGuid(); if ( Guid.TryParse( workflowName, out workflowTypeGuid ) ) { var rockContext = new RockContext(); var workflowTypeService = new WorkflowTypeService(rockContext); var workflowType = workflowTypeService.Get( workflowTypeGuid ); if ( workflowType != null ) { var workflow = Rock.Model.Workflow.Activate( workflowType, workflowName ); List<string> workflowErrors; if ( workflow.Process( rockContext, out workflowErrors ) ) { if ( workflow.IsPersisted || workflowType.IsPersisted ) { var workflowService = new Rock.Model.WorkflowService(rockContext); workflowService.Add( workflow ); rockContext.WrapTransaction( () => { rockContext.SaveChanges(); workflow.SaveAttributeValues( rockContext ); foreach ( var activity in workflow.Activities ) { activity.SaveAttributeValues( rockContext ); } } ); } } } } }
/// <summary> /// Launch the workflow /// </summary> protected void LaunchTheWorkflow(string workflowName) { Guid workflowTypeGuid = Guid.NewGuid(); if (Guid.TryParse(workflowName, out workflowTypeGuid)) { var rockContext = new RockContext(); var workflowTypeService = new WorkflowTypeService(rockContext); var workflowType = workflowTypeService.Get(workflowTypeGuid); if (workflowType != null) { var workflow = Rock.Model.Workflow.Activate(workflowType, workflowName); List <string> workflowErrors; if (workflow.Process(rockContext, out workflowErrors)) { if (workflow.IsPersisted || workflowType.IsPersisted) { var workflowService = new Rock.Model.WorkflowService(rockContext); workflowService.Add(workflow); rockContext.WrapTransaction(() => { rockContext.SaveChanges(); workflow.SaveAttributeValues(rockContext); foreach (var activity in workflow.Activities) { activity.SaveAttributeValues(rockContext); } }); } } } } }
private void LaunchWorkflow(RockContext rockContext, ConnectionWorkflow connectionWorkflow, string name) { var workflowTypeService = new WorkflowTypeService(rockContext); var workflowType = workflowTypeService.Get(connectionWorkflow.WorkflowTypeId.Value); if (workflowType != null) { ConnectionRequest connectionRequest = null; if (ConnectionRequestGuid.HasValue) { connectionRequest = new ConnectionRequestService(rockContext).Get(ConnectionRequestGuid.Value); var workflow = Rock.Model.Workflow.Activate(workflowType, name); List <string> workflowErrors; new WorkflowService(rockContext).Process(workflow, connectionRequest, out workflowErrors); if (workflow.Id != 0) { ConnectionRequestWorkflow connectionRequestWorkflow = new ConnectionRequestWorkflow(); connectionRequestWorkflow.ConnectionRequestId = connectionRequest.Id; connectionRequestWorkflow.WorkflowId = workflow.Id; connectionRequestWorkflow.ConnectionWorkflowId = connectionWorkflow.Id; connectionRequestWorkflow.TriggerType = connectionWorkflow.TriggerType; connectionRequestWorkflow.TriggerQualifier = connectionWorkflow.QualifierValue; new ConnectionRequestWorkflowService(rockContext).Add(connectionRequestWorkflow); rockContext.SaveChanges(); } } } }
public BlockActionResult SaveForm(Guid formGuid, FormSettingsViewModel formSettings) { if (formGuid == Guid.Empty || formSettings == null) { return(ActionBadRequest("Invalid parameters provided.")); } using (var rockContext = new RockContext()) { var formBuilderEntityTypeId = EntityTypeCache.Get(typeof(Rock.Workflow.Action.FormBuilder)).Id; var workflowType = new WorkflowTypeService(rockContext).Get(formGuid); if (workflowType == null || !workflowType.IsFormBuilder) { return(ActionBadRequest("Specified workflow type is not a form builder.")); } // Find the action type that represents the form. var actionForm = workflowType.ActivityTypes .SelectMany(a => a.ActionTypes) .Where(a => a.EntityTypeId == formBuilderEntityTypeId) .FirstOrDefault(); if (actionForm == null || actionForm.WorkflowForm == null) { return(ActionBadRequest("Specified workflow is not properly configured for use in form builder.")); } UpdateWorkflowType(formSettings, actionForm.WorkflowForm, workflowType, rockContext); rockContext.SaveChanges(); return(ActionOk()); } }
/// <summary> /// Sets the edit value from IEntity.Id value /// </summary> /// <param name="control">The control.</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="id">The identifier.</param> public void SetEditValueFromEntityId(Control control, Dictionary <string, ConfigurationValue> configurationValues, int?id) { var item = new WorkflowTypeService(new RockContext()).Get(id ?? 0); string guidValue = item != null?item.Guid.ToString() : string.Empty; SetEditValue(control, configurationValues, guidValue); }
/// <summary> /// Returns the field's current value(s) /// </summary> /// <param name="parentControl">The parent control.</param> /// <param name="value">Information about the value</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param> /// <returns></returns> public override string FormatValue(Control parentControl, string value, Dictionary <string, ConfigurationValue> configurationValues, bool condensed) { string formattedValue = string.Empty; if (!string.IsNullOrWhiteSpace(value)) { var names = new List <string>(); var guids = new List <Guid>(); foreach (string guidValue in value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { Guid?guid = guidValue.AsGuidOrNull(); if (guid.HasValue) { guids.Add(guid.Value); } } if (guids.Any()) { using (var rockContext = new RockContext()) { var workflowTypes = new WorkflowTypeService(rockContext).Queryable().AsNoTracking().Where(a => guids.Contains(a.Guid)); if (workflowTypes.Any()) { formattedValue = string.Join(", ", (from workflowType in workflowTypes select workflowType.Name).ToArray()); } } } } return(base.FormatValue(parentControl, formattedValue, null, condensed)); }
private void LaunchWorkflow(RockContext rockContext, int workflowTypeId, string name) { var workflowTypeService = new WorkflowTypeService(rockContext); var workflowType = workflowTypeService.Get(workflowTypeId); if (workflowType != null) { var workflow = Rock.Model.Workflow.Activate(workflowType, name); if (workflow.AttributeValues != null) { if (workflow.AttributeValues.ContainsKey("Group")) { var group = new GroupService(rockContext).Get(GroupId.Value); if (group != null) { workflow.AttributeValues["Group"].Value = group.Guid.ToString(); } } if (workflow.AttributeValues.ContainsKey("Person")) { var personAlias = new PersonAliasService(rockContext).Get(PersonAliasId.Value); if (personAlias != null) { workflow.AttributeValues["Person"].Value = personAlias.Guid.ToString(); } } } List <string> workflowErrors; new Rock.Model.WorkflowService(rockContext).Process(workflow, null, out workflowErrors); } }
/// <summary> /// Gets the expression. /// </summary> /// <param name="entityType"></param> /// <param name="serviceInstance">The service instance.</param> /// <param name="parameterExpression">The parameter expression.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection) { if (!string.IsNullOrWhiteSpace(selection)) { var values = JsonConvert.DeserializeObject <List <string> >(selection); if (values.Count >= 3) { var workflowType = new WorkflowTypeService(new RockContext()).Get(values[0].AsGuid()); if (workflowType != null) { string selectedProperty = values[1]; var entityFields = GetWorkflowAttributes(workflowType.Id); var entityField = entityFields.FindFromFilterSelection(selectedProperty); if (entityField != null) { return(GetAttributeExpression(serviceInstance, parameterExpression, entityField, values.Skip(2).ToList())); } } } } return(null); }
/// <summary> /// Sets the selection. /// </summary> /// <param name="entityType"></param> /// <param name="controls">The controls.</param> /// <param name="selection">The selection.</param> public override void SetSelection(Type entityType, Control[] controls, string selection) { if (!string.IsNullOrWhiteSpace(selection)) { var values = JsonConvert.DeserializeObject <List <string> >(selection); if (controls.Length > 0 && values.Count > 0) { var workflowType = new WorkflowTypeService(new RockContext()).Get(values[0].AsGuid()); if (workflowType != null) { var containerControl = controls[0] as DynamicControlsPanel; if (containerControl.Controls.Count > 0) { WorkflowTypePicker workflowTypePicker = containerControl.Controls[0] as WorkflowTypePicker; workflowTypePicker.SetValue(workflowType.Id); workflowTypePicker_SelectItem(workflowTypePicker, new EventArgs()); } if (containerControl.Controls.Count > 1 && values.Count > 1) { DropDownList ddlProperty = containerControl.Controls[1] as DropDownList; var entityFields = GetWorkflowAttributes(workflowType.Id); var panelControls = new List <Control>(); panelControls.AddRange(containerControl.Controls.OfType <Control>()); SetEntityFieldSelection(entityFields, ddlProperty, values.Skip(1).ToList(), panelControls); } } } } }
/// <summary> /// Executes this instance. /// </summary> public void Execute() { using (var rockContext = new RockContext()) { var workflowTypeService = new WorkflowTypeService(rockContext); WorkflowType workflowType = null; if (WorkflowTypeGuid.HasValue) { workflowType = workflowTypeService.Get(WorkflowTypeGuid.Value); } if (workflowType == null && WorkflowTypeId.HasValue) { workflowType = workflowTypeService.Get(WorkflowTypeId.Value); } if (workflowType != null) { var workflow = Rock.Model.Workflow.Activate(workflowType, WorkflowName); foreach (var keyVal in WorkflowAttributeValues) { workflow.SetAttributeValue(keyVal.Key, keyVal.Value); } List <string> workflowErrors; new Rock.Model.WorkflowService(rockContext).Process(workflow, GetEntity(), out workflowErrors); } } }
/// <summary> /// Handles the FileUploaded event of the fsFile control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void fsFile_FileUploaded(object sender, EventArgs e) { using (new Rock.Data.UnitOfWorkScope()) { var binaryFileService = new BinaryFileService(); BinaryFile binaryFile = null; if (fsFile.BinaryFileId.HasValue) { binaryFile = binaryFileService.Get(fsFile.BinaryFileId.Value); } if (binaryFile != null) { if (!string.IsNullOrWhiteSpace(tbName.Text)) { binaryFile.FileName = tbName.Text; } // set binaryFile.Id to original id since the UploadedFile is a temporary binaryFile with a different id binaryFile.Id = hfBinaryFileId.ValueAsInt(); binaryFile.Description = tbDescription.Text; binaryFile.BinaryFileTypeId = ddlBinaryFileType.SelectedValueAsInt(); if (binaryFile.BinaryFileTypeId.HasValue) { binaryFile.BinaryFileType = new BinaryFileTypeService().Get(binaryFile.BinaryFileTypeId.Value); } binaryFile.LoadAttributes(); Rock.Attribute.Helper.GetEditValues(phAttributes, binaryFile); // Process uploaded file using an optional workflow Guid workflowTypeGuid = Guid.NewGuid(); if (Guid.TryParse(GetAttributeValue("Workflow"), out workflowTypeGuid)) { var workflowTypeService = new WorkflowTypeService(); var workflowType = workflowTypeService.Get(workflowTypeGuid); if (workflowType != null) { var workflow = Workflow.Activate(workflowType, binaryFile.FileName); List <string> workflowErrors; if (workflow.Process(binaryFile, out workflowErrors)) { binaryFile = binaryFileService.Get(binaryFile.Id); if (workflowType.IsPersisted) { var workflowService = new Rock.Model.WorkflowService(); workflowService.Add(workflow, CurrentPersonId); workflowService.Save(workflow, CurrentPersonId); } } } } ShowBinaryFileDetail(binaryFile); } } }
/// <summary> /// Activates and processes a workflow activity. If the workflow has not yet been activated, it will /// also be activated /// </summary> /// <param name="activityName">Name of the activity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.Exception"></exception> protected bool ProcessActivity(string activityName, out List <string> errorMessages) { errorMessages = new List <string>(); Guid?guid = GetAttributeValue("WorkflowType").AsGuidOrNull(); if (guid.HasValue) { using (var rockContext = new RockContext()) { var workflowTypeService = new WorkflowTypeService(rockContext); var workflowService = new WorkflowService(rockContext); var workflowType = workflowTypeService.Queryable("ActivityTypes") .Where(w => w.Guid.Equals(guid.Value)) .FirstOrDefault(); if (workflowType != null) { if (CurrentWorkflow == null) { CurrentWorkflow = Rock.Model.Workflow.Activate(workflowType, CurrentCheckInState.Kiosk.Device.Name, rockContext); if (Request["Override"] != null) { if (Request["Override"].ToString() == "True") { CurrentWorkflow.SetAttributeValue("Override", "True"); } } } var activityType = workflowType.ActivityTypes.Where(a => a.Name == activityName).FirstOrDefault(); if (activityType != null) { WorkflowActivity.Activate(activityType, CurrentWorkflow, rockContext); if (workflowService.Process(CurrentWorkflow, CurrentCheckInState, out errorMessages)) { // Keep workflow active for continued processing CurrentWorkflow.CompletedDateTime = null; return(true); } } else { errorMessages.Add(string.Format("Workflow type does not have a '{0}' activity type", activityName)); } } else { errorMessages.Add("Invalid Workflow Type"); } } } return(false); }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> public override bool Execute( RockContext rockContext, WorkflowAction action, Object entity, out List<string> errorMessages ) { errorMessages = new List<string>(); var guid = GetAttributeValue( action, "Workflow" ).AsGuid(); if (guid.IsEmpty()) { action.AddLogEntry( "Invalid Workflow Property", true ); return false; } var currentActivity = action.Activity; var newWorkflowType = new WorkflowTypeService( rockContext ).Get( guid ); var newWorkflowName = GetAttributeValue(action, "WorkflowName" ); if (newWorkflowType == null) { action.AddLogEntry( "Invalid Workflow Property", true ); return false; } var newWorkflow = Rock.Model.Workflow.Activate( newWorkflowType, newWorkflowName ); if (newWorkflow == null) { action.AddLogEntry( "The Workflow could not be activated", true ); return false; } CopyAttributes( newWorkflow, currentActivity, rockContext ); SaveForProcessingLater( newWorkflow, rockContext ); return true; // Kick off processing of new Workflow /*if(newWorkflow.Process( rockContext, entity, out errorMessages )) { if (newWorkflow.IsPersisted || newWorkflowType.IsPersisted) { var workflowService = new Rock.Model.WorkflowService( rockContext ); workflowService.Add( newWorkflow ); rockContext.WrapTransaction( () => { rockContext.SaveChanges(); newWorkflow.SaveAttributeValues( rockContext ); foreach (var activity in newWorkflow.Activities) { activity.SaveAttributeValues( rockContext ); } } ); } return true; } else { return false; }*/ }
/// <summary> /// User has clicked on the "Settings" button in the admin panel. /// </summary> protected override void ShowSettings() { Group group = new GroupService(new RockContext()).Get(GetAttributeValue("Group").AsGuid()); // // Fill in the General section. // if (group != null && group.Id != 0) { gpSettingsGroup.SetValue(group); grpSettingsRole.GroupTypeId = group.GroupTypeId; grpSettingsRole.GroupRoleId = GetAttributeValue("GroupRole").AsInteger(); grpSettingsRole.Visible = true; } else { gpSettingsGroup.SetValue(null); grpSettingsRole.Visible = false; } ddlSettingsAddAsStatus.BindToEnum <GroupMemberStatus>(true, new GroupMemberStatus[] { GroupMemberStatus.Inactive }); ddlSettingsAddAsStatus.SelectedValue = GetAttributeValue("AddAsStatus"); ddlSettingsRequestMemberAttributes.SelectedValue = GetAttributeValue("RequestMemberAttributes"); ppCancelPage.SetValue(new PageService(new RockContext()).Get(GetAttributeValue("CancelPage").AsGuid())); // // Fill in the Limitation section. // cbSettingsAllowRemove.Checked = GetAttributeValue("AllowRemove").AsBoolean(); nbSettingsMinimumSelection.Text = GetAttributeValue("MinimumSelection"); nbSettingsMaximumSelection.Text = GetAttributeValue("MaximumSelection"); // // Fill in the Post-Save Actions section. // wtpSettingsIndividualWorkflow.SetValue((!string.IsNullOrWhiteSpace(GetAttributeValue("IndividualWorkflow")) ? new WorkflowTypeService(new RockContext()).Get(GetAttributeValue("IndividualWorkflow").AsGuid()) : null)); var submissionWorkflowType = new WorkflowTypeService(new RockContext()).Get(GetAttributeValue("SubmissionWorkflow").AsGuid()); wtpSettingsSubmissionWorkflow.SetValue((submissionWorkflowType != null ? submissionWorkflowType : null)); string selection = GetAttributeValue("SubmissionAttribute"); LoadSubmissionWorkflowAttributes(submissionWorkflowType); ddlSettingsSubmissionAttribute.SelectedValue = ddlSettingsSubmissionAttribute.Items.FindByValue(selection) != null ? selection : string.Empty; ppSettingsSaveRedirectPage.SetValue((!string.IsNullOrWhiteSpace(GetAttributeValue("SaveRedirectPage")) ? new PageService(new RockContext()).Get(GetAttributeValue("SaveRedirectPage").AsGuid()) : null)); ceSettingsSavedTemplate.Text = GetAttributeValue("SavedTemplate"); // // Fill in the User Interface section. // tbSettingsSubmitTitle.Text = GetAttributeValue("SubmitTitle"); tbSettingsHeaderTitle.Text = GetAttributeValue("HeaderTitle"); cbSettingsKioskMode.Checked = GetAttributeValue("KioskMode").AsBoolean(false); ceSettingsContentTemplate.Text = GetAttributeValue("ContentTemplate"); cbSettingsLavaDebug.Checked = GetAttributeValue("LavaDebug").AsBoolean(); pnlSettingsModal.Visible = true; mdSettings.Show(); }
private static int LoadByGuid2(Guid guid, RockContext rockContext) { var WorkflowTypeService = new WorkflowTypeService(rockContext); return(WorkflowTypeService .Queryable().AsNoTracking() .Where(c => c.Guid.Equals(guid)) .Select(c => c.Id) .FirstOrDefault()); }
public HttpResponseMessage Family(string param) { try { var Session = HttpContext.Current.Session; CurrentKioskId = ( int )Session["CheckInKioskId"]; Guid blockGuid = ( Guid )Session["BlockGuid"]; List <int> CheckInGroupTypeIds = (List <int>)Session["CheckInGroupTypeIds"]; CurrentCheckInState = new CheckInState(CurrentKioskId, null, CheckInGroupTypeIds); CurrentCheckInState.CheckIn.UserEnteredSearch = true; CurrentCheckInState.CheckIn.ConfirmSingleFamily = true; CurrentCheckInState.CheckIn.SearchType = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_PHONE_NUMBER); CurrentCheckInState.CheckIn.SearchValue = param; var rockContext = new Rock.Data.RockContext(); var block = BlockCache.Read(blockGuid, rockContext); string workflowActivity = block.GetAttributeValue("WorkflowActivity"); Guid? workflowGuid = block.GetAttributeValue("WorkflowType").AsGuidOrNull(); List <string> errors; var workflowTypeService = new WorkflowTypeService(rockContext); var workflowService = new WorkflowService(rockContext); var workflowType = workflowTypeService.Queryable("ActivityTypes") .Where(w => w.Guid.Equals(workflowGuid.Value)) .FirstOrDefault(); var CurrentWorkflow = Rock.Model.Workflow.Activate(workflowType, CurrentCheckInState.Kiosk.Device.Name, rockContext); var activityType = workflowType.ActivityTypes.Where(a => a.Name == workflowActivity).FirstOrDefault(); if (activityType != null) { WorkflowActivity.Activate(activityType, CurrentWorkflow, rockContext); if (workflowService.Process(CurrentWorkflow, CurrentCheckInState, out errors)) { // Keep workflow active for continued processing CurrentWorkflow.CompletedDateTime = null; SaveState(Session); List <CheckInFamily> families = CurrentCheckInState.CheckIn.Families; families = families.OrderBy(f => f.Caption).ToList(); return(ControllerContext.Request.CreateResponse(HttpStatusCode.OK, families)); } } else { return(ControllerContext.Request.CreateResponse(HttpStatusCode.InternalServerError, string.Format("Workflow type does not have a '{0}' activity type", workflowActivity))); } return(ControllerContext.Request.CreateResponse(HttpStatusCode.InternalServerError, String.Join("\n", errors))); } catch (Exception ex) { ExceptionLogService.LogException(ex, HttpContext.Current); return(ControllerContext.Request.CreateResponse(HttpStatusCode.Forbidden, "Forbidden")); } }
private void NavigateToWorkflow(string personAliasGuid) { RockContext rockContext = new RockContext(); WorkflowTypeService workflowTypeService = new WorkflowTypeService(rockContext); var workflowGuid = GetAttributeValue("EditWorkflow"); var workflowId = workflowTypeService.Get(workflowGuid.AsGuid()).Id.ToString(); NavigateToLinkedPage("WorkflowPage", new Dictionary <string, string> { { "WorkflowTypeId", workflowId }, { "PersonGuid", personAliasGuid } }); }
protected void gReleventPeople_RowSelected(object sender, RowEventArgs e) { var attendance = new AttendanceService(rockContext).Get(SelectedAttendanceGuid); var selectedPlegePersonAlias = new PersonAliasService(rockContext).Get(( Guid )e.RowKeyValue); var workflowType = new WorkflowTypeService(rockContext).Get(GetAttributeValue("WorkflowType").AsGuid()); if (attendance != null && selectedPlegePersonAlias != null) { LaunchWorkflow(rockContext, attendance, selectedPlegePersonAlias, workflowType); } }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages) { errorMessages = new List <string>(); var guid = GetAttributeValue(action, "Workflow").AsGuid(); if (guid.IsEmpty()) { action.AddLogEntry("Invalid Workflow Property", true); return(false); } var currentActivity = action.Activity; var newWorkflowType = new WorkflowTypeService(rockContext).Get(guid); var newWorkflowName = GetAttributeValue(action, "WorkflowName"); var mergeFields = GetMergeFields(action); newWorkflowName = newWorkflowName.ResolveMergeFields(mergeFields); if (newWorkflowType == null) { action.AddLogEntry("Invalid Workflow Property", true); return(false); } var newWorkflow = Rock.Model.Workflow.Activate(newWorkflowType, newWorkflowName); if (newWorkflow == null) { action.AddLogEntry("The Workflow could not be activated", true); return(false); } CopyAttributes(newWorkflow, currentActivity, rockContext); // Set Initiator in workflow as current person newWorkflow.InitiatorPersonAlias = action.Activity.Workflow.InitiatorPersonAlias; newWorkflow.InitiatorPersonAliasId = action.Activity.Workflow.InitiatorPersonAliasId; newWorkflow.CreatedByPersonAlias = action.Activity.Workflow.CreatedByPersonAlias; newWorkflow.CreatedByPersonAliasId = action.Activity.Workflow.CreatedByPersonAliasId; SaveForProcessingLater(newWorkflow, rockContext); // Process new workflow try { new WorkflowService(rockContext).Process(newWorkflow, out errorMessages); } catch (Exception e) { action.AddLogEntry(string.Format("The Workflow couldn't be processed: {0}", e.Message)); } return(true); }
protected void SelectMember_Click(object sender, Rock.Web.UI.Controls.RowEventArgs e) { RockContext rockContext = new RockContext(); WorkflowTypeService workflowTypeService = new WorkflowTypeService(rockContext); var groupMemberGuid = (( Guid )e.RowKeyValue).ToString(); var workflowGuid = GetAttributeValue("EditWorkflow"); var workflowId = workflowTypeService.Get(workflowGuid.AsGuid()).Id.ToString(); NavigateToLinkedPage("WorkflowPage", new Dictionary <string, string> { { "WorkflowTypeId", workflowId }, { "GroupMemberGuid", groupMemberGuid } }); }
/// <summary> /// Sets the selection. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="controls">The controls.</param> /// <param name="selection">The selection.</param> public override void SetSelection(Type entityType, Control[] controls, string selection) { string[] selectionValues = selection.Split('|'); if (selectionValues.Length >= 1) { var workflowType = new WorkflowTypeService(new RockContext()).Get(selectionValues[0].AsGuid()); if (workflowType != null) { (controls[0] as WorkflowTypePicker).SetValue(workflowType.Id); } } }
protected void bntMerge_Click(object sender, EventArgs e) { PDFWorkflowObject pdfWorkflowObject = new PDFWorkflowObject(); pdfWorkflowObject.LavaInput = ceLava.Text; pdfWorkflowObject.MergeObjects = new Dictionary <string, object>(); if (cbCurrentPerson.Checked) { pdfWorkflowObject.MergeObjects.Add("CurrentPerson", CurrentPerson); } if (cbGlobal.Checked) { pdfWorkflowObject.MergeObjects.Add("GlobalAttributes", GlobalAttributesCache.Read()); } Guid workflowTypeGuid = Guid.NewGuid(); if (Guid.TryParse(GetAttributeValue("WorkflowType"), out workflowTypeGuid)) { var workflowRockContext = new RockContext(); var workflowTypeService = new WorkflowTypeService(workflowRockContext); var workflowType = workflowTypeService.Get(workflowTypeGuid); if (workflowType != null) { var workflow = Workflow.Activate(workflowType, "PDFLavaWorkflow"); List <string> workflowErrors; var workflowService = new WorkflowService(workflowRockContext); var workflowActivity = GetAttributeValue("WorkflowActivity"); var activityType = workflowType.ActivityTypes.Where(a => a.Name == workflowActivity).FirstOrDefault(); if (activityType != null) { WorkflowActivity.Activate(activityType, workflow, workflowRockContext); if (workflowService.Process(workflow, pdfWorkflowObject, out workflowErrors)) { //success } } } } RockContext rockContext = new RockContext(); BinaryFileService binaryFileService = new BinaryFileService(rockContext); pdfWorkflowObject.RenderedPDF.FileName = "LavaGeneratedPDF.pdf"; binaryFileService.Add(pdfWorkflowObject.RenderedPDF); rockContext.SaveChanges(); Response.Redirect(pdfWorkflowObject.RenderedPDF.Path); }
/// <summary> /// Gets the selection. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="controls">The controls.</param> /// <returns></returns> public override string GetSelection(Type entityType, Control[] controls) { int? workflowTypeId = (controls[0] as WorkflowTypePicker).SelectedValueAsId(); Guid?workflowTypeGuid = null; var workflowType = new WorkflowTypeService(new RockContext()).Get(workflowTypeId ?? 0); if (workflowType != null) { workflowTypeGuid = workflowType.Guid; } return(workflowTypeGuid.ToString()); }
protected void lbTransferAnotherLine_OnClick(object sender, EventArgs e) { var rockContext = new RockContext(); var personService = new PersonService(rockContext); var followUp = personService.Get(ppFollowUp.SelectedValue.Value); var workflowTypeGuid = GetAttributeValue("ReassignWorkflowType").AsGuidOrNull(); if (workflowTypeGuid.HasValue && ppAnotherLineNewConsolidator.SelectedValue.HasValue) { var workflowTypeService = new WorkflowTypeService(rockContext); var workflowType = workflowTypeService.Get(workflowTypeGuid.Value); if (workflowType != null) { try { List <string> workflowErrors; var workflow = Workflow.Activate(workflowType, followUp.FullName); if (workflow.AttributeValues != null) { if (workflow.AttributeValues.ContainsKey(GetAttributeValue("ReassignAttributeKey"))) { var personAlias = new PersonAliasService(rockContext).Get(ppAnotherLineNewConsolidator.PersonAliasId.Value); if (personAlias != null) { workflow.AttributeValues[GetAttributeValue("ReassignAttributeKey")].Value = personAlias.Guid.ToString(); } } } new WorkflowService(rockContext).Process(workflow, followUp.PrimaryAlias, out workflowErrors); if (!workflowErrors.Any()) { var queryParms = new Dictionary <string, string> { { "success", "true" }, { "type", "transfer" }, { "personId", ppFollowUp.PersonId.ToString() } }; NavigateToParentPage(queryParms); } } catch (Exception ex) { ExceptionLogService.LogException(ex, this.Context); } } } }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List<string> errorMessages) { errorMessages = new List<string>(); var workflowTypeGuid = GetAttributeValue(action, "WorkflowType").AsGuidOrNull(); var workflowName = GetAttributeValue(action, "WorkflowName"); if (workflowTypeGuid.HasValue && !string.IsNullOrEmpty(workflowName)) { var sourceKeyMap = new Dictionary<string, string>(); var workflowAttributeKeys = GetAttributeValue(action, "WorkflowAttributeKey"); if (!string.IsNullOrWhiteSpace(workflowAttributeKeys)) { //TODO Find a way upstream to stop an additional being appended to the value sourceKeyMap = workflowAttributeKeys.AsDictionaryOrNull(); var workflowTypeService = new WorkflowTypeService(rockContext); var workflow = Rock.Model.Workflow.Activate(workflowTypeService.Get(workflowTypeGuid.Value), workflowName); workflow.LoadAttributes(rockContext); foreach (var keyPair in sourceKeyMap) { //Does the source key exist as an attribute in the source workflow? if (action.Activity.Workflow.Attributes.ContainsKey(keyPair.Key)) { if (workflow.Attributes.ContainsKey(keyPair.Value)) { var value = action.Activity.Workflow.AttributeValues[keyPair.Key].Value; workflow.SetAttributeValue(keyPair.Value, value); } else { errorMessages.Add(string.Format("{0} not a key in {1}", keyPair.Value, action.Activity.Workflow.Name)); } } else { errorMessages.Add(string.Format("{0} not a key in {1}", keyPair.Key, workflowName)); } } new Rock.Model.WorkflowService(rockContext).Process(workflow, out errorMessages); } } else { errorMessages.Add("Workflow type or name not provided"); } return true; }
/// <summary> /// Handles the Click event of the btnDefault control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnDefault_Click(object sender, EventArgs e) { var bioBlock = BlockCache.Get(Rock.SystemGuid.Block.BIO.AsGuid()); List <Guid> workflowActionGuidList = bioBlock.GetAttributeValues("WorkflowActions").AsGuidList(); if (workflowActionGuidList == null || workflowActionGuidList.Count == 0) { // Add Checkr to Bio Workflow Actions bioBlock.SetAttributeValue("WorkflowActions", CheckrSystemGuid.CHECKR_WORKFLOW_TYPE); } else { //var workflowActionValues = workflowActionValue.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ).ToList(); Guid guid = CheckrSystemGuid.CHECKR_WORKFLOW_TYPE.AsGuid(); if (!workflowActionGuidList.Any(w => w == guid)) { // Add Checkr to Bio Workflow Actions workflowActionGuidList.Add(guid); } // Remove PMM from Bio Workflow Actions guid = Rock.SystemGuid.WorkflowType.PROTECTMYMINISTRY.AsGuid(); workflowActionGuidList.RemoveAll(w => w == guid); bioBlock.SetAttributeValue("WorkflowActions", workflowActionGuidList.AsDelimited(",")); } bioBlock.SaveAttributeValue("WorkflowActions"); string checkrTypeName = (typeof(Rock.Checkr.Checkr)).FullName; var checkrComponent = BackgroundCheckContainer.Instance.Components.Values.FirstOrDefault(c => c.Value.TypeName == checkrTypeName); checkrComponent.Value.SetAttributeValue("Active", "True"); checkrComponent.Value.SaveAttributeValue("Active"); using (var rockContext = new RockContext()) { WorkflowTypeService workflowTypeService = new WorkflowTypeService(rockContext); // Rename PMM Workflow var pmmWorkflowAction = workflowTypeService.Get(Rock.SystemGuid.WorkflowType.PROTECTMYMINISTRY.AsGuid()); pmmWorkflowAction.Name = Checkr_CreatePages.NEW_PMM_WORKFLOW_TYPE_NAME; var checkrWorkflowAction = workflowTypeService.Get(CheckrSystemGuid.CHECKR_WORKFLOW_TYPE.AsGuid()); // Rename Checkr Workflow checkrWorkflowAction.Name = "Background Check"; rockContext.SaveChanges(); } ShowDetail(); }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages) { errorMessages = new List <string>(); var workflowTypeGuid = GetAttributeValue(action, "WorkflowType").AsGuidOrNull(); var workflowName = GetAttributeValue(action, "WorkflowName"); if (workflowTypeGuid.HasValue && !string.IsNullOrEmpty(workflowName)) { var sourceKeyMap = new Dictionary <string, string>(); var workflowAttributeKeys = GetAttributeValue(action, "WorkflowAttributeKey"); if (!string.IsNullOrWhiteSpace(workflowAttributeKeys)) { //TODO Find a way upstream to stop an additional being appended to the value sourceKeyMap = workflowAttributeKeys.AsDictionaryOrNull(); var workflowTypeService = new WorkflowTypeService(rockContext); var workflow = Rock.Model.Workflow.Activate(workflowTypeService.Get(workflowTypeGuid.Value), workflowName); workflow.LoadAttributes(rockContext); foreach (var keyPair in sourceKeyMap) { //Does the source key exist as an attribute in the source workflow? if (action.Activity.Workflow.Attributes.ContainsKey(keyPair.Key)) { if (workflow.Attributes.ContainsKey(keyPair.Value)) { var value = action.Activity.Workflow.AttributeValues[keyPair.Key].Value; workflow.SetAttributeValue(keyPair.Value, value); } else { errorMessages.Add(string.Format("{0} not a key in {1}", keyPair.Value, action.Activity.Workflow.Name)); } } else { errorMessages.Add(string.Format("{0} not a key in {1}", keyPair.Key, workflowName)); } } new Rock.Model.WorkflowService(rockContext).Process(workflow, out errorMessages); } } else { errorMessages.Add("Workflow type or name not provided"); } return(true); }
/// <summary> /// Launch the workflow /// </summary> protected void LaunchTheWorkflow(string workflowName) { Guid workflowTypeGuid = Guid.NewGuid(); if ( Guid.TryParse( workflowName, out workflowTypeGuid ) ) { var rockContext = new RockContext(); var workflowTypeService = new WorkflowTypeService(rockContext); var workflowType = workflowTypeService.Get( workflowTypeGuid ); if ( workflowType != null ) { var workflow = Rock.Model.Workflow.Activate( workflowType, workflowName ); List<string> workflowErrors; new Rock.Model.WorkflowService( rockContext ).Process( workflow, out workflowErrors ); } } }
/// <summary> /// Returns the field's current value(s) /// </summary> /// <param name="parentControl">The parent control.</param> /// <param name="value">Information about the value</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param> /// <returns></returns> public override string FormatValue( Control parentControl, string value, Dictionary<string, ConfigurationValue> configurationValues, bool condensed ) { string formattedValue = string.Empty; Guid workflowTypeGuid = Guid.Empty; if (Guid.TryParse( value, out workflowTypeGuid )) { var workflowtype = new WorkflowTypeService().Get( workflowTypeGuid ); if ( workflowtype != null ) { formattedValue = workflowtype.Name; } } return base.FormatValue( parentControl, formattedValue, null, condensed ); }
/// <summary> /// Launch the workflow /// </summary> protected void LaunchTheWorkflow( string workflowName, IJobExecutionContext context ) { Guid workflowTypeGuid = Guid.NewGuid(); if ( Guid.TryParse( workflowName, out workflowTypeGuid ) ) { var rockContext = new RockContext(); var workflowTypeService = new WorkflowTypeService( rockContext ); var workflowType = workflowTypeService.Get( workflowTypeGuid ); if ( workflowType != null ) { var workflow = Rock.Model.Workflow.Activate( workflowType, workflowName ); List<string> workflowErrors; var processed = new Rock.Model.WorkflowService( rockContext ).Process( workflow, out workflowErrors ); context.Result = ( processed ? "Processed " : "Did not process " ) + workflow.ToString(); } } }
/// <summary> /// Execute method to write transaction to the database. /// </summary> public void Execute() { if ( Trigger != null ) { using ( var rockContext = new RockContext() ) { var workflowTypeService = new WorkflowTypeService( rockContext ); var workflowType = workflowTypeService.Get( Trigger.WorkflowTypeId ); if ( workflowType != null ) { var workflow = Rock.Model.Workflow.Activate( workflowType, Trigger.WorkflowName ); List<string> workflowErrors; new Rock.Model.WorkflowService( rockContext ).Process( workflow, Entity, out workflowErrors ); } } } }
/// <summary> /// Returns the field's current value(s) /// </summary> /// <param name="parentControl">The parent control.</param> /// <param name="value">Information about the value</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param> /// <returns></returns> public override string FormatValue( Control parentControl, string value, Dictionary<string, ConfigurationValue> configurationValues, bool condensed ) { string formattedValue = string.Empty; if ( !string.IsNullOrWhiteSpace( value ) ) { Guid? guid = value.AsGuidOrNull(); if ( guid.HasValue ) { var workflowType = new WorkflowTypeService( new RockContext() ) .Queryable().FirstOrDefault( a => a.Guid.Equals( guid.Value ) ); if ( workflowType != null ) { formattedValue = workflowType.Name; } } } return base.FormatValue( parentControl, formattedValue, null, condensed ); }
/// <summary> /// Creates the HTML controls required to configure this type of field /// </summary> /// <returns></returns> public override List<Control> ConfigurationControls() { var controls = base.ConfigurationControls(); // build a drop down list of defined types (the one that gets selected is // used to build a list of defined values) var ddl = new RockDropDownList(); controls.Add( ddl ); ddl.AutoPostBack = true; ddl.SelectedIndexChanged += OnQualifierUpdated; ddl.Label = "Workflow Type"; ddl.Help = "Workflow Type to select workflows from, if left blank any workflow type's workflows can be selected."; ddl.Items.Add( new ListItem() ); var workflowTypeService = new WorkflowTypeService( new RockContext() ); var workflowTypes = workflowTypeService.Queryable().OrderBy( a => a.Name ).ToList(); workflowTypes.ForEach( g => ddl.Items.Add( new ListItem( g.Name, g.Id.ToString().ToUpper() ) ) ); return controls; }
/// <summary> /// Execute method to write transaction to the database. /// </summary> public void Execute() { if ( Trigger != null ) { var workflowTypeService = new WorkflowTypeService(); var workflowType = workflowTypeService.Get( Trigger.WorkflowTypeId ); if ( workflowType != null ) { var workflow = Rock.Model.Workflow.Activate( workflowType, Trigger.WorkflowName ); List<string> workflowErrors; if ( workflow.Process( Entity, out workflowErrors ) ) { if ( workflowType.IsPersisted ) { var workflowService = new Rock.Model.WorkflowService(); workflowService.Add( workflow, PersonId ); workflowService.Save( workflow, PersonId ); } } } } }
/// <summary> /// Launch the workflow /// </summary> protected void LaunchTheWorkflow(string workflowName) { Guid workflowTypeGuid = Guid.NewGuid(); if ( Guid.TryParse( workflowName, out workflowTypeGuid ) ) { var workflowTypeService = new WorkflowTypeService(); var workflowType = workflowTypeService.Get( workflowTypeGuid ); if ( workflowType != null ) { var workflow = Rock.Model.Workflow.Activate( workflowType, workflowName ); List<string> workflowErrors; if ( workflow.Process( out workflowErrors ) ) { if ( workflowType.IsPersisted ) { var workflowService = new Rock.Model.WorkflowService(); workflowService.Add( workflow, CurrentPersonId ); workflowService.Save( workflow, CurrentPersonId ); } } } } }
protected void lbProfileNext_Click( object sender, EventArgs e ) { // setup merge fields var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields( this.RockPage, this.CurrentPerson ); mergeFields.Add( "PersonId", hfPersonId.Value ); mergeFields.Add( "FirstName", tbFirstName.Text ); mergeFields.Add( "LastName", tbLastName.Text ); mergeFields.Add( "StreetAddress", acAddress.Street1 ); mergeFields.Add( "City", acAddress.City ); mergeFields.Add( "State", acAddress.State ); mergeFields.Add( "PostalCode", acAddress.PostalCode ); mergeFields.Add( "Country", acAddress.Country ); mergeFields.Add( "Email", tbEmail.Text ); mergeFields.Add( "HomePhone", pnbHomePhone.Text ); mergeFields.Add( "MobilePhone", pnbHomePhone.Text ); mergeFields.Add( "BirthDate", dpBirthdate.Text ); mergeFields.Add( "OtherUpdates", tbOtherUpdates.Text ); // if an email was provided email results RockContext rockContext = new RockContext(); if ( !string.IsNullOrWhiteSpace( GetAttributeValue( "UpdateEmail" ) ) ) { var receiptEmail = new SystemEmailService( rockContext ).Get( new Guid( GetAttributeValue( "UpdateEmail" ) ) ); if ( receiptEmail != null ) { var appRoot = Rock.Web.Cache.GlobalAttributesCache.Read( rockContext ).GetValue( "PublicApplicationRoot" ); var recipients = new List<RecipientData>(); recipients.Add( new RecipientData( null, mergeFields ) ); Email.Send( receiptEmail.Guid, recipients, appRoot ); } } // launch workflow if configured if ( !string.IsNullOrWhiteSpace( GetAttributeValue( "WorkflowType" ) ) ) { var workflowTypeService = new WorkflowTypeService( rockContext ); var workflowService = new WorkflowService( rockContext ); var workflowType = workflowTypeService.Get( new Guid( GetAttributeValue( "WorkflowType" ) ) ); if ( workflowType != null ) { var workflow = Rock.Model.Workflow.Activate( workflowType, "Kiosk Update Info" ); // set attributes workflow.SetAttributeValue( "PersonId", hfPersonId.Value ); workflow.SetAttributeValue( "FirstName", tbFirstName.Text ); workflow.SetAttributeValue( "LastName", tbLastName.Text ); workflow.SetAttributeValue( "StreetAddress", acAddress.Street1 ); workflow.SetAttributeValue( "City", acAddress.City ); workflow.SetAttributeValue( "State", acAddress.State ); workflow.SetAttributeValue( "PostalCode", acAddress.PostalCode ); workflow.SetAttributeValue( "Country", acAddress.Country ); workflow.SetAttributeValue( "Email", tbEmail.Text ); workflow.SetAttributeValue( "HomePhone", pnbHomePhone.Text ); workflow.SetAttributeValue( "MobilePhone", pnbHomePhone.Text ); workflow.SetAttributeValue( "BirthDate", dpBirthdate.Text ); workflow.SetAttributeValue( "OtherUpdates", tbOtherUpdates.Text ); // lauch workflow List<string> workflowErrors; workflowService.Process( workflow, out workflowErrors ); } } HidePanels(); pnlComplete.Visible = true; lCompleteMessage.Text = GetAttributeValue( "CompleteMessageLava" ).ResolveMergeFields( mergeFields ); bool enableDebug = GetAttributeValue( "EnableDebug" ).AsBoolean(); if ( enableDebug && IsUserAuthorized( Authorization.EDIT ) ) { lDebug.Visible = true; lDebug.Text = mergeFields.lavaDebugInfo(); } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click( object sender, EventArgs e ) { var rockContext = new RockContext(); WorkflowType workflowType; WorkflowTypeService service = new WorkflowTypeService( rockContext ); int workflowTypeId = int.Parse( hfWorkflowTypeId.Value ); if ( workflowTypeId == 0 ) { workflowType = new WorkflowType(); workflowType.IsSystem = false; workflowType.Name = string.Empty; } else { workflowType = service.Get( workflowTypeId ); } workflowType.Name = tbName.Text; workflowType.Description = tbDescription.Text; workflowType.CategoryId = cpCategory.SelectedValueAsInt(); workflowType.Order = 0; workflowType.WorkTerm = tbWorkTerm.Text; if ( !string.IsNullOrWhiteSpace( tbProcessingInterval.Text ) ) { workflowType.ProcessingIntervalSeconds = int.Parse( tbProcessingInterval.Text ); } workflowType.IsPersisted = cbIsPersisted.Checked; workflowType.LoggingLevel = ddlLoggingLevel.SelectedValueAsEnum<WorkflowLoggingLevel>(); workflowType.IsActive = cbIsActive.Checked; if ( !Page.IsValid ) { return; } if ( !workflowType.IsValid ) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction( () => { // Save the entity field changes to workflow type if ( workflowType.Id.Equals( 0 ) ) { service.Add( workflowType ); } rockContext.SaveChanges(); // Save the attributes SaveAttributes( new Workflow().TypeId, "WorkflowTypeId", workflowType.Id.ToString(), AttributesState, rockContext ); WorkflowActivityTypeService workflowActivityTypeService = new WorkflowActivityTypeService( rockContext ); WorkflowActionTypeService workflowActionTypeService = new WorkflowActionTypeService( rockContext ); WorkflowActionFormService workflowFormService = new WorkflowActionFormService( rockContext ); WorkflowActionFormAttributeService workflowFormAttributeService = new WorkflowActionFormAttributeService( rockContext ); // delete WorkflowActionTypes that aren't assigned in the UI anymore List<WorkflowActivityEditor> workflowActivityTypeEditorList = phActivities.Controls.OfType<WorkflowActivityEditor>().ToList(); List<WorkflowActionType> actionTypesInDB = workflowActionTypeService.Queryable().Where( a => a.ActivityType.WorkflowTypeId.Equals( workflowType.Id ) ).ToList(); List<WorkflowActionType> actionTypesInUI = new List<WorkflowActionType>(); foreach ( WorkflowActivityEditor workflowActivityTypeEditor in workflowActivityTypeEditorList ) { foreach ( WorkflowActionEditor editor in workflowActivityTypeEditor.Controls.OfType<WorkflowActionEditor>() ) { actionTypesInUI.Add( editor.WorkflowActionType ); } } var deletedActionTypes = from actionType in actionTypesInDB where !actionTypesInUI.Select( u => u.Guid ).Contains( actionType.Guid ) select actionType; deletedActionTypes.ToList().ForEach( actionType => { if (actionType.WorkflowForm != null) { workflowFormService.Delete( actionType.WorkflowForm ); } workflowActionTypeService.Delete( actionType ); } ); rockContext.SaveChanges(); // delete WorkflowActivityTypes that aren't assigned in the UI anymore List<WorkflowActivityType> activityTypesInDB = workflowActivityTypeService.Queryable().Where( a => a.WorkflowTypeId.Equals( workflowType.Id ) ).ToList(); List<WorkflowActivityType> activityTypesInUI = workflowActivityTypeEditorList.Select( a => a.GetWorkflowActivityType() ).ToList(); var deletedActivityTypes = from activityType in activityTypesInDB where !activityTypesInUI.Select( u => u.Guid ).Contains( activityType.Guid ) select activityType; deletedActivityTypes.ToList().ForEach( activityType => { workflowActivityTypeService.Delete( activityType ); } ); rockContext.SaveChanges(); // add or update WorkflowActivityTypes(and Actions) that are assigned in the UI int workflowActivityTypeOrder = 0; foreach ( WorkflowActivityEditor workflowActivityTypeEditor in workflowActivityTypeEditorList ) { // Add or Update the activity type WorkflowActivityType editorWorkflowActivityType = workflowActivityTypeEditor.GetWorkflowActivityType(); WorkflowActivityType workflowActivityType = workflowType.ActivityTypes.FirstOrDefault( a => a.Guid.Equals( editorWorkflowActivityType.Guid ) ); if ( workflowActivityType == null ) { workflowActivityType = new WorkflowActivityType(); workflowType.ActivityTypes.Add( workflowActivityType ); } workflowActivityType.IsActive = editorWorkflowActivityType.IsActive; workflowActivityType.Name = editorWorkflowActivityType.Name; workflowActivityType.Description = editorWorkflowActivityType.Description; workflowActivityType.IsActivatedWithWorkflow = editorWorkflowActivityType.IsActivatedWithWorkflow; workflowActivityType.Order = workflowActivityTypeOrder++; int workflowActionTypeOrder = 0; foreach ( WorkflowActionEditor workflowActionTypeEditor in workflowActivityTypeEditor.Controls.OfType<WorkflowActionEditor>() ) { WorkflowActionType editorWorkflowActionType = workflowActionTypeEditor.WorkflowActionType; WorkflowActionType workflowActionType = workflowActivityType.ActionTypes.FirstOrDefault( a => a.Guid.Equals( editorWorkflowActionType.Guid ) ); if ( workflowActionType == null ) { // New action workflowActionType = new WorkflowActionType(); workflowActivityType.ActionTypes.Add( workflowActionType ); } workflowActionType.Name = editorWorkflowActionType.Name; workflowActionType.EntityTypeId = editorWorkflowActionType.EntityTypeId; workflowActionType.IsActionCompletedOnSuccess = editorWorkflowActionType.IsActionCompletedOnSuccess; workflowActionType.IsActivityCompletedOnSuccess = editorWorkflowActionType.IsActivityCompletedOnSuccess; workflowActionType.Attributes = editorWorkflowActionType.Attributes; workflowActionType.AttributeValues = editorWorkflowActionType.AttributeValues; workflowActionType.Order = workflowActionTypeOrder++; if ( workflowActionType.WorkflowForm != null && editorWorkflowActionType.WorkflowForm == null ) { // Form removed workflowFormService.Delete( workflowActionType.WorkflowForm ); workflowActionType.WorkflowForm = null; } if (editorWorkflowActionType.WorkflowForm != null) { if (workflowActionType.WorkflowForm == null) { workflowActionType.WorkflowForm = new WorkflowActionForm(); } workflowActionType.WorkflowForm.Header = editorWorkflowActionType.WorkflowForm.Header; workflowActionType.WorkflowForm.Footer = editorWorkflowActionType.WorkflowForm.Footer; workflowActionType.WorkflowForm.InactiveMessage = editorWorkflowActionType.WorkflowForm.InactiveMessage; workflowActionType.WorkflowForm.Actions = editorWorkflowActionType.WorkflowForm.Actions; var editorGuids = editorWorkflowActionType.WorkflowForm.FormAttributes .Select( a => a.Attribute.Guid) .ToList(); foreach( var formAttribute in workflowActionType.WorkflowForm.FormAttributes .Where( a => !editorGuids.Contains(a.Attribute.Guid) ) ) { workflowFormAttributeService.Delete(formAttribute); } int attributeOrder = 0; foreach ( var editorAttribute in editorWorkflowActionType.WorkflowForm.FormAttributes.OrderBy( a => a.Order ) ) { int attributeId = AttributeCache.Read( editorAttribute.Attribute.Guid ).Id; var formAttribute = workflowActionType.WorkflowForm.FormAttributes .Where( a => a.AttributeId == attributeId ) .FirstOrDefault(); if (formAttribute == null) { formAttribute = new WorkflowActionFormAttribute(); formAttribute.Guid = editorAttribute.Guid; formAttribute.AttributeId = attributeId; workflowActionType.WorkflowForm.FormAttributes.Add( formAttribute ); } formAttribute.Order = attributeOrder++; formAttribute.IsVisible = editorAttribute.IsVisible; formAttribute.IsReadOnly = editorAttribute.IsReadOnly; formAttribute.IsRequired = editorAttribute.IsRequired; } } } } rockContext.SaveChanges(); foreach ( var activityType in workflowType.ActivityTypes ) { foreach ( var workflowActionType in activityType.ActionTypes ) { workflowActionType.SaveAttributeValues( rockContext ); } } } ); var qryParams = new Dictionary<string, string>(); qryParams["workflowTypeId"] = workflowType.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); }
/// <summary> /// Handles the Click event of the btnEdit control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnEdit_Click( object sender, EventArgs e ) { var rockContext = new RockContext(); WorkflowTypeService service = new WorkflowTypeService( rockContext ); WorkflowType item = service.Get( int.Parse( hfWorkflowTypeId.Value ) ); ShowEditDetails( item, rockContext ); }
/// <summary> /// Handles the Click event of the btnCancel control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnCancel_Click( object sender, EventArgs e ) { if ( hfWorkflowTypeId.Value.Equals( "0" ) ) { int? parentCategoryId = PageParameter( "ParentCategoryId" ).AsInteger( false ); if ( parentCategoryId.HasValue ) { // Cancelling on Add, and we know the parentCategoryId, so we are probably in treeview mode, so navigate to the current page var qryParams = new Dictionary<string, string>(); qryParams["CategoryId"] = parentCategoryId.ToString(); NavigateToPage( RockPage.Guid, qryParams ); } else { // Cancelling on Add. Return to Grid NavigateToParentPage(); } } else { // Cancelling on Edit. Return to Details WorkflowTypeService service = new WorkflowTypeService( new RockContext() ); WorkflowType item = service.Get( int.Parse( hfWorkflowTypeId.Value ) ); ShowReadonlyDetails( item ); } }
/// <summary> /// Shows the detail. /// </summary> /// <param name="itemKey">The item key.</param> /// <param name="itemKeyValue">The item key value.</param> /// <param name="parentCategoryId">The parent category id.</param> public void ShowDetail( string itemKey, int itemKeyValue, int? parentCategoryId ) { if ( !itemKey.Equals( "workflowTypeId" ) ) { pnlDetails.Visible = false; return; } var rockContext = new RockContext(); WorkflowType workflowType = null; if ( !itemKeyValue.Equals( 0 ) ) { workflowType = new WorkflowTypeService( rockContext ).Get( itemKeyValue ); } else { workflowType = new WorkflowType { Id = 0, IsActive = true, IsPersisted = true, IsSystem = false, CategoryId = parentCategoryId }; workflowType.ActivityTypes.Add( new WorkflowActivityType { Guid = Guid.NewGuid(), IsActive = true } ); } if ( workflowType == null ) { return; } pnlDetails.Visible = true; hfWorkflowTypeId.Value = workflowType.Id.ToString(); // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; if ( !IsUserAuthorized( Authorization.EDIT ) ) { readOnly = true; nbEditModeMessage.Heading = "Information"; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( WorkflowType.FriendlyTypeName ); } if ( workflowType.IsSystem ) { readOnly = true; nbEditModeMessage.Heading = "Information"; nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( WorkflowType.FriendlyTypeName ); } if ( readOnly ) { btnEdit.Visible = false; ShowReadonlyDetails( workflowType ); } else { btnEdit.Visible = true; if ( workflowType.Id > 0 ) { ShowReadonlyDetails( workflowType ); } else { ShowEditDetails( workflowType, rockContext ); } } }
/// <summary> /// Gets the entity fields. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="includeOnlyReportingFields">if set to <c>true</c> [include only reporting fields].</param> /// <param name="limitToFilterableFields">if set to <c>true</c> [limit to filterable fields].</param> /// <returns></returns> public static List<EntityField> GetEntityFields( Type entityType, bool includeOnlyReportingFields = true, bool limitToFilterableFields = true ) { List<EntityField> entityFields = null; _workflowTypeNameLookup = null; if ( HttpContext.Current != null ) { entityFields = HttpContext.Current.Items[EntityHelper.GetCacheKey(entityType, includeOnlyReportingFields, limitToFilterableFields)] as List<EntityField>; if ( entityFields != null ) { return entityFields; } } if ( entityFields == null ) { entityFields = new List<EntityField>(); } // Find all non-virtual properties or properties that have the [IncludeForReporting] attribute var entityProperties = entityType.GetProperties().ToList(); var filteredEntityProperties = entityProperties .Where( p => !p.GetGetMethod().IsVirtual || p.GetCustomAttributes( typeof( IncludeForReportingAttribute ), true ).Any() || p.Name == "Order" ) .ToList(); // Get Properties foreach ( var property in filteredEntityProperties ) { bool isReportable = !property.GetCustomAttributes( typeof( HideFromReportingAttribute ), true ).Any(); if ( !includeOnlyReportingFields || isReportable ) { EntityField entityField = new EntityField( property.Name, FieldKind.Property, property ); entityField.IsPreviewable = property.GetCustomAttributes( typeof( PreviewableAttribute ), true ).Any(); var fieldTypeAttribute = property.GetCustomAttribute<Rock.Data.FieldTypeAttribute>(); // check if we can set it from the fieldTypeAttribute if ( ( fieldTypeAttribute != null ) && SetEntityFieldFromFieldTypeAttribute( entityField, fieldTypeAttribute ) ) { // intentially blank, entity field is already setup } // Enum Properties else if ( property.PropertyType.IsEnum ) { entityField.FieldType = FieldTypeCache.Read( SystemGuid.FieldType.SINGLE_SELECT.AsGuid() ); var list = new List<string>(); foreach ( var value in Enum.GetValues( property.PropertyType ) ) { list.Add( string.Format( "{0}^{1}", value, value.ToString().SplitCase() ) ); } var listSource = string.Join( ",", list ); entityField.FieldConfig.Add( "values", new Field.ConfigurationValue( listSource ) ); entityField.FieldConfig.Add( "fieldtype", new Field.ConfigurationValue( "rb" ) ); } // Boolean properties else if ( property.PropertyType == typeof( bool ) || property.PropertyType == typeof( bool? ) ) { entityField.FieldType = FieldTypeCache.Read( SystemGuid.FieldType.BOOLEAN.AsGuid() ); } // Datetime properties else if ( property.PropertyType == typeof( DateTime ) || property.PropertyType == typeof( DateTime? ) ) { var colAttr = property.GetCustomAttributes( typeof( ColumnAttribute ), true ).FirstOrDefault(); if ( colAttr != null && ( (ColumnAttribute)colAttr ).TypeName == "Date" ) { entityField.FieldType = FieldTypeCache.Read( SystemGuid.FieldType.DATE.AsGuid() ); } else { entityField.FieldType = FieldTypeCache.Read( SystemGuid.FieldType.DATE_TIME.AsGuid() ); } } // Decimal properties else if ( property.PropertyType == typeof( decimal ) || property.PropertyType == typeof( decimal? ) ) { entityField.FieldType = FieldTypeCache.Read( SystemGuid.FieldType.DECIMAL.AsGuid() ); } // Text Properties else if ( property.PropertyType == typeof( string ) ) { entityField.FieldType = FieldTypeCache.Read( SystemGuid.FieldType.TEXT.AsGuid() ); } // Integer Properties (which may be a DefinedValue) else if ( property.PropertyType == typeof( int ) || property.PropertyType == typeof( int? ) ) { entityField.FieldType = FieldTypeCache.Read( SystemGuid.FieldType.INTEGER.AsGuid() ); var definedValueAttribute = property.GetCustomAttribute<Rock.Data.DefinedValueAttribute>(); if ( definedValueAttribute != null ) { // Defined Value Properties Guid? definedTypeGuid = ( (Rock.Data.DefinedValueAttribute)definedValueAttribute ).DefinedTypeGuid; if ( definedTypeGuid.HasValue ) { var definedType = DefinedTypeCache.Read( definedTypeGuid.Value ); entityField.Title = definedType != null ? definedType.Name : property.Name.Replace( "ValueId", string.Empty ).SplitCase(); if ( definedType != null ) { entityField.FieldType = FieldTypeCache.Read( SystemGuid.FieldType.DEFINED_VALUE.AsGuid() ); entityField.FieldConfig.Add( "definedtype", new Field.ConfigurationValue( definedType.Id.ToString() ) ); } } } } if ( entityField != null && entityField.FieldType != null ) { entityFields.Add( entityField ); } } } // Get Attributes var entityTypeCache = EntityTypeCache.Read( entityType, true ); if ( entityTypeCache != null ) { int entityTypeId = entityTypeCache.Id; using ( var rockContext = new RockContext() ) { var qryAttributes = new AttributeService( rockContext ).Queryable().Where( a => a.EntityTypeId == entityTypeId ); if ( entityType == typeof( Group ) ) { // in the case of Group, show attributes that are entity global, but also ones that are qualified by GroupTypeId qryAttributes = qryAttributes .Where( a => a.EntityTypeQualifierColumn == null || a.EntityTypeQualifierColumn == string.Empty || a.EntityTypeQualifierColumn == "GroupTypeId" ); } else if ( entityType == typeof( ContentChannelItem ) ) { // in the case of ContentChannelItem, show attributes that are entity global, but also ones that are qualified by ContentChannelTypeId qryAttributes = qryAttributes .Where( a => a.EntityTypeQualifierColumn == null || a.EntityTypeQualifierColumn == string.Empty || a.EntityTypeQualifierColumn == "ContentChannelTypeId" ); } else if ( entityType == typeof( Rock.Model.Workflow ) ) { // in the case of Workflow, show attributes that are entity global, but also ones that are qualified by WorkflowTypeId (and have a valid WorkflowTypeId) var validWorkflowTypeIds = new WorkflowTypeService(rockContext).Queryable().Select(a=> a.Id).ToList().Select(a => a.ToString()).ToList(); qryAttributes = qryAttributes .Where( a => a.EntityTypeQualifierColumn == null || a.EntityTypeQualifierColumn == string.Empty || (a.EntityTypeQualifierColumn == "WorkflowTypeId" && validWorkflowTypeIds.Contains(a.EntityTypeQualifierValue) )); } else { qryAttributes = qryAttributes.Where( a => a.EntityTypeQualifierColumn == string.Empty && a.EntityTypeQualifierValue == string.Empty ); } var attributeIdList = qryAttributes.Select( a => a.Id ).ToList(); foreach ( var attributeId in attributeIdList ) { AddEntityFieldForAttribute( entityFields, AttributeCache.Read( attributeId ), limitToFilterableFields ); } } } // Order the fields by title, name int index = 0; var sortedFields = new List<EntityField>(); foreach ( var entityField in entityFields.OrderBy( p => !string.IsNullOrEmpty(p.AttributeEntityTypeQualifierName)).ThenBy( p => p.Title ).ThenBy( p => p.Name ) ) { entityField.Index = index; index++; sortedFields.Add( entityField ); } if ( HttpContext.Current != null ) { HttpContext.Current.Items[EntityHelper.GetCacheKey( entityType, includeOnlyReportingFields, limitToFilterableFields )] = sortedFields; } return sortedFields; }
/// <summary> /// Reads new values entered by the user for the field ( as Guid ) /// </summary> /// <param name="control">Parent control that controls were added to in the CreateEditControl() method</param> /// <param name="configurationValues"></param> /// <returns></returns> public override string GetEditValue( Control control, Dictionary<string, ConfigurationValue> configurationValues ) { var picker = control as WorkflowTypePicker; string result = null; if ( picker != null ) { var ids = picker.SelectedValuesAsInt(); var workflowTypes = new WorkflowTypeService( new RockContext() ).Queryable().Where( a => ids.Contains( a.Id ) ); if ( workflowTypes.Any() ) { result = workflowTypes.Select( s => s.Guid.ToString() ).ToList().AsDelimited( "," ); } } return result; }
/// <summary> /// Shows the detail. /// </summary> private void ShowDetail() { int? workflowTypeId = PageParameter( "workflowTypeId" ).AsIntegerOrNull(); int? parentCategoryId = PageParameter( "ParentCategoryId" ).AsIntegerOrNull(); if ( !workflowTypeId.HasValue ) { pnlDetails.Visible = false; return; } var rockContext = new RockContext(); WorkflowType workflowType = null; if ( workflowTypeId.Value.Equals( 0 ) ) { workflowType = new WorkflowType(); workflowType.Id = 0; workflowType.IsActive = true; workflowType.IsPersisted = true; workflowType.IsSystem = false; workflowType.CategoryId = parentCategoryId; workflowType.IconCssClass = "fa fa-list-ol"; workflowType.ActivityTypes.Add( new WorkflowActivityType { Name = "Start", Guid = Guid.NewGuid(), IsActive = true, IsActivatedWithWorkflow = true } ); workflowType.WorkTerm = "Work"; workflowType.ProcessingIntervalSeconds = 28800; // Default to every 8 hours workflowType.SummaryViewText = GetAttributeValue( "DefaultSummaryViewText" ); workflowType.NoActionMessage = GetAttributeValue( "DefaultNoActionMessage" ); // hide the panel drawer that show created and last modified dates pdAuditDetails.Visible = false; } else { workflowType = new WorkflowTypeService( rockContext ).Get( workflowTypeId.Value ); pdAuditDetails.SetEntity( workflowType, ResolveRockUrl( "~" ) ); } if ( workflowType == null ) { return; } pnlDetails.Visible = true; hfWorkflowTypeId.Value = workflowType.Id.ToString(); // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; // User must have 'Edit' rights to block, or 'Administrate' rights to workflow type if ( !IsUserAuthorized( Authorization.EDIT ) ) { readOnly = true; nbEditModeMessage.Heading = "Information"; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( WorkflowType.FriendlyTypeName ); } if ( workflowType.IsSystem ) { readOnly = true; nbEditModeMessage.Heading = "Information"; nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( WorkflowType.FriendlyTypeName ); } if ( readOnly ) { btnEdit.Visible = false; btnSecurity.Visible = false; ShowReadonlyDetails( workflowType ); } else { btnEdit.Visible = true; btnSecurity.Title = "Secure " + workflowType.Name; btnSecurity.EntityId = workflowType.Id; if ( workflowType.Id > 0 ) { ShowReadonlyDetails( workflowType ); } else { LoadStateDetails(workflowType, rockContext); ShowEditDetails( workflowType, rockContext ); } } }
private List<WorkflowNavigationCategory> GetData() { int entityTypeId = EntityTypeCache.Read( typeof( Rock.Model.WorkflowType ) ).Id; var selectedCategories = new List<Guid>(); GetAttributeValue( "Categories" ).SplitDelimitedValues().ToList().ForEach( c => selectedCategories.Add( c.AsGuid() ) ); bool includeChildCategories = GetAttributeValue( "IncludeChildCategories" ).AsBoolean(); var rockContext = new RockContext(); var categories = new CategoryService( rockContext ).GetNavigationItems( entityTypeId, selectedCategories, includeChildCategories, CurrentPerson ); var workflowTypes = new WorkflowTypeService( rockContext ).Queryable( "ActivityTypes.ActionTypes" ).ToList(); return GetWorkflowNavigationCategories( categories, workflowTypes ); }
/// <summary> /// Handles the Click event of the btnDelete control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnDelete_Click( object sender, EventArgs e ) { var rockContext = new RockContext(); var service = new WorkflowTypeService( rockContext ); var workflowType = service.Get( int.Parse( hfWorkflowTypeId.Value ) ); if ( workflowType != null ) { if ( !workflowType.IsAuthorized( Authorization.ADMINISTRATE, this.CurrentPerson ) ) { mdDeleteWarning.Show( "You are not authorized to delete this workflow type.", ModalAlertType.Information ); return; } service.Delete( workflowType ); rockContext.SaveChanges(); } // reload page var qryParams = new Dictionary<string, string>(); NavigateToPage( RockPage.Guid, qryParams ); }
/// <summary> /// Handles the Click event of the btnEdit control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnEdit_Click( object sender, EventArgs e ) { var rockContext = new RockContext(); var workflowType = new WorkflowTypeService( rockContext ).Get( hfWorkflowTypeId.Value.AsInteger() ); LoadStateDetails( workflowType, rockContext ); ShowEditDetails( workflowType, rockContext ); }
/// <summary> /// Handles the Click event of the lbSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void lbSave_Click( object sender, EventArgs e ) { if ( _group != null && _occurrence != null ) { var rockContext = new RockContext(); var attendanceService = new AttendanceService( rockContext ); var personAliasService = new PersonAliasService( rockContext ); var locationService = new LocationService( rockContext ); bool dateAdjusted = false; DateTime startDate = _occurrence.Date; // If this is a manuall entered occurrence, check to see if date was changed if ( !_occurrence.ScheduleId.HasValue ) { DateTime? originalDate = PageParameter( "Date" ).AsDateTime(); if ( originalDate.HasValue && originalDate.Value.Date != startDate.Date ) { startDate = originalDate.Value.Date; dateAdjusted = true; } } DateTime endDate = startDate.AddDays( 1 ); var existingAttendees = attendanceService .Queryable( "PersonAlias" ) .Where( a => a.GroupId == _group.Id && a.LocationId == _occurrence.LocationId && a.ScheduleId == _occurrence.ScheduleId && a.StartDateTime >= startDate && a.StartDateTime < endDate ); if ( dateAdjusted ) { foreach ( var attendee in existingAttendees ) { attendee.StartDateTime = _occurrence.Date; } } // If did not meet was selected and this was a manually entered occurrence (not based on a schedule/location) // then just delete all the attendance records instead of tracking a 'did not meet' value if ( cbDidNotMeet.Checked && !_occurrence.ScheduleId.HasValue ) { foreach ( var attendance in existingAttendees ) { attendanceService.Delete( attendance ); } } else { int? campusId = locationService.GetCampusIdForLocation( _occurrence.LocationId ); if ( !campusId.HasValue ) { campusId = _group.CampusId; } if ( !campusId.HasValue && _allowCampusFilter ) { var campus = CampusCache.Read( bddlCampus.SelectedValueAsInt() ?? 0 ); if ( campus != null ) { campusId = campus.Id; } } if ( cbDidNotMeet.Checked ) { // If the occurrence is based on a schedule, set the did not meet flags foreach ( var attendance in existingAttendees ) { attendance.DidAttend = null; attendance.DidNotOccur = true; } } foreach ( var attendee in _attendees ) { var attendance = existingAttendees .Where( a => a.PersonAlias.PersonId == attendee.PersonId ) .FirstOrDefault(); if ( attendance == null ) { int? personAliasId = personAliasService.GetPrimaryAliasId( attendee.PersonId ); if ( personAliasId.HasValue ) { attendance = new Attendance(); attendance.GroupId = _group.Id; attendance.ScheduleId = _group.ScheduleId; attendance.PersonAliasId = personAliasId; attendance.StartDateTime = _occurrence.Date.Date.Add( _occurrence.StartTime ); attendance.LocationId = _occurrence.LocationId; attendance.CampusId = campusId; attendance.ScheduleId = _occurrence.ScheduleId; // check that the attendance record is valid cvAttendance.IsValid = attendance.IsValid; if ( !cvAttendance.IsValid ) { cvAttendance.ErrorMessage = attendance.ValidationResults.Select( a => a.ErrorMessage ).ToList().AsDelimited( "<br />" ); return; } attendanceService.Add( attendance ); } } if ( attendance != null ) { if ( cbDidNotMeet.Checked ) { attendance.DidAttend = null; attendance.DidNotOccur = true; } else { attendance.DidAttend = attendee.Attended; attendance.DidNotOccur = null; } } } } if ( _occurrence.LocationId.HasValue ) { Rock.CheckIn.KioskLocationAttendance.Flush( _occurrence.LocationId.Value ); } rockContext.SaveChanges(); WorkflowType workflowType = null; Guid? workflowTypeGuid = GetAttributeValue( "Workflow" ).AsGuidOrNull(); if ( workflowTypeGuid.HasValue ) { var workflowTypeService = new WorkflowTypeService( rockContext ); workflowType = workflowTypeService.Get( workflowTypeGuid.Value ); if ( workflowType != null ) { try { var workflow = Workflow.Activate( workflowType, _group.Name ); workflow.SetAttributeValue( "StartDateTime", _occurrence.Date.ToString( "o" ) ); workflow.SetAttributeValue( "Schedule", _group.Schedule.Guid.ToString() ); List<string> workflowErrors; new WorkflowService( rockContext ).Process( workflow, _group, out workflowErrors ); } catch ( Exception ex ) { ExceptionLogService.LogException( ex, this.Context ); } } } var qryParams = new Dictionary<string, string> { { "GroupId", _group.Id.ToString() } }; var groupTypeIds = PageParameter( "GroupTypeIds" ); if ( !string.IsNullOrWhiteSpace( groupTypeIds ) ) { qryParams.Add( "GroupTypeIds", groupTypeIds ); } NavigateToParentPage( qryParams ); } }
/// <summary> /// Sets the value. ( as Guid ) /// </summary> /// <param name="control">The control.</param> /// <param name="configurationValues"></param> /// <param name="value">The value.</param> public override void SetEditValue( Control control, Dictionary<string, ConfigurationValue> configurationValues, string value ) { if ( value != null ) { var picker = control as WorkflowTypePicker; if ( picker != null ) { var guids = new List<Guid>(); foreach ( string guidValue in value.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ) ) { Guid? guid = guidValue.AsGuidOrNull(); if ( guid.HasValue ) { guids.Add( guid.Value ); } } if ( guids.Any() ) { var workflowTypes = new WorkflowTypeService( new RockContext() ).Queryable().Where( a => guids.Contains( a.Guid ) ).ToList(); picker.SetValues( workflowTypes ); } } } }
/// <summary> /// Handles the Click event of the btnCopy control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnCopy_Click( object sender, EventArgs e ) { var rockContext = new RockContext(); var workflowType = new WorkflowTypeService( rockContext ).Get( hfWorkflowTypeId.Value.AsInteger() ); if ( workflowType != null ) { // Load the state objects for the source workflow type LoadStateDetails( workflowType, rockContext ); // clone the workflow type var newWorkflowType = workflowType.Clone( false ); newWorkflowType.CreatedByPersonAlias = null; newWorkflowType.CreatedByPersonAliasId = null; newWorkflowType.CreatedDateTime = RockDateTime.Now; newWorkflowType.ModifiedByPersonAlias = null; newWorkflowType.ModifiedByPersonAliasId = null; newWorkflowType.ModifiedDateTime = RockDateTime.Now; newWorkflowType.Id = 0; newWorkflowType.Guid = Guid.NewGuid(); newWorkflowType.IsSystem = false; newWorkflowType.Name = workflowType.Name + " - Copy"; // Create temporary state objects for the new workflow type var newAttributesState = new List<Attribute>(); var newActivityTypesState = new List<WorkflowActivityType>(); var newActivityAttributesState = new Dictionary<Guid, List<Attribute>>(); // Dictionary to keep the attributes and activity types linked between the source and the target based on their guids var guidXref = new Dictionary<Guid, Guid>(); // Clone the workflow attributes foreach ( var attribute in AttributesState ) { var newAttribute = attribute.Clone( false ); newAttribute.Id = 0; newAttribute.Guid = Guid.NewGuid(); newAttribute.IsSystem = false; newAttributesState.Add( newAttribute ); guidXref.Add( attribute.Guid, newAttribute.Guid ); foreach ( var qualifier in attribute.AttributeQualifiers ) { var newQualifier = qualifier.Clone( false ); newQualifier.Id = 0; newQualifier.Guid = Guid.NewGuid(); newQualifier.IsSystem = false; newAttribute.AttributeQualifiers.Add( qualifier ); guidXref.Add( qualifier.Guid, newQualifier.Guid ); } } // Create new guids for all the existing activity types foreach (var activityType in ActivityTypesState) { guidXref.Add( activityType.Guid, Guid.NewGuid() ); } foreach ( var activityType in ActivityTypesState ) { var newActivityType = activityType.Clone( false ); newActivityType.WorkflowTypeId = 0; newActivityType.Id = 0; newActivityType.Guid = guidXref[activityType.Guid]; newActivityTypesState.Add( newActivityType ); var newActivityAttributes = new List<Attribute>(); foreach ( var attribute in ActivityAttributesState[activityType.Guid] ) { var newAttribute = attribute.Clone( false ); newAttribute.Id = 0; newAttribute.Guid = Guid.NewGuid(); newAttribute.IsSystem = false; newActivityAttributes.Add( newAttribute ); guidXref.Add( attribute.Guid, newAttribute.Guid ); foreach ( var qualifier in attribute.AttributeQualifiers ) { var newQualifier = qualifier.Clone( false ); newQualifier.Id = 0; newQualifier.Guid = Guid.NewGuid(); newQualifier.IsSystem = false; newAttribute.AttributeQualifiers.Add( qualifier ); guidXref.Add( qualifier.Guid, newQualifier.Guid ); } } newActivityAttributesState.Add( newActivityType.Guid, newActivityAttributes ); foreach ( var actionType in activityType.ActionTypes ) { var newActionType = actionType.Clone( false ); newActionType.ActivityTypeId = 0; newActionType.WorkflowFormId = 0; newActionType.Id = 0; newActionType.Guid = Guid.NewGuid(); newActivityType.ActionTypes.Add( newActionType ); if ( actionType.CriteriaAttributeGuid.HasValue && guidXref.ContainsKey( actionType.CriteriaAttributeGuid.Value ) ) { newActionType.CriteriaAttributeGuid = guidXref[actionType.CriteriaAttributeGuid.Value]; } Guid criteriaAttributeGuid = actionType.CriteriaValue.AsGuid(); if ( !criteriaAttributeGuid.IsEmpty() && guidXref.ContainsKey( criteriaAttributeGuid ) ) { newActionType.CriteriaValue = guidXref[criteriaAttributeGuid].ToString(); } if ( actionType.WorkflowForm != null ) { var newWorkflowForm = actionType.WorkflowForm.Clone( false ); newWorkflowForm.Id = 0; newWorkflowForm.Guid = Guid.NewGuid(); var newActionButtons = new List<string>(); foreach ( var actionButton in actionType.WorkflowForm.Actions.Split( new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries ) ) { var details = actionButton.Split( new char[] { '^' } ); if ( details.Length > 2 ) { Guid oldGuid = details[2].AsGuid(); if (!oldGuid.IsEmpty() && guidXref.ContainsKey(oldGuid)) { details[2] = guidXref[oldGuid].ToString(); } } newActionButtons.Add( details.ToList().AsDelimited("^") ); } newWorkflowForm.Actions = newActionButtons.AsDelimited( "|" ); if ( actionType.WorkflowForm.ActionAttributeGuid.HasValue && guidXref.ContainsKey( actionType.WorkflowForm.ActionAttributeGuid.Value ) ) { newWorkflowForm.ActionAttributeGuid = guidXref[actionType.WorkflowForm.ActionAttributeGuid.Value]; } newActionType.WorkflowForm = newWorkflowForm; foreach ( var formAttribute in actionType.WorkflowForm.FormAttributes ) { if ( guidXref.ContainsKey( formAttribute.Attribute.Guid ) ) { var newFormAttribute = formAttribute.Clone( false ); newFormAttribute.WorkflowActionFormId = 0; newFormAttribute.Id = 0; newFormAttribute.Guid = Guid.NewGuid(); newFormAttribute.AttributeId = 0; newFormAttribute.Attribute = new Rock.Model.Attribute { Guid = guidXref[formAttribute.Attribute.Guid], Name = formAttribute.Attribute.Name }; newWorkflowForm.FormAttributes.Add( newFormAttribute ); } } } newActionType.LoadAttributes( rockContext ); if ( actionType.Attributes != null && actionType.Attributes.Any() ) { foreach ( var attributeKey in actionType.Attributes.Select( a => a.Key ) ) { string value = actionType.GetAttributeValue( attributeKey ); Guid guidValue = value.AsGuid(); if ( !guidValue.IsEmpty() && guidXref.ContainsKey( guidValue ) ) { newActionType.SetAttributeValue( attributeKey, guidXref[guidValue].ToString() ); } else { newActionType.SetAttributeValue( attributeKey, value ); } } } } } workflowType = newWorkflowType; AttributesState = newAttributesState; ActivityTypesState = newActivityTypesState; ActivityAttributesState = newActivityAttributesState; hfWorkflowTypeId.Value = workflowType.Id.ToString(); ShowEditDetails( workflowType, rockContext ); } }
/// <summary> /// Restores the view-state information from a previous user control request that was saved by the <see cref="M:System.Web.UI.UserControl.SaveViewState" /> method. /// </summary> /// <param name="savedState">An <see cref="T:System.Object" /> that represents the user control state to be restored.</param> protected override void LoadViewState( object savedState ) { base.LoadViewState( savedState ); string json = ViewState["Workflow"] as string; if ( string.IsNullOrWhiteSpace( json ) ) { Workflow = new Workflow(); } else { Workflow = JsonConvert.DeserializeObject<Workflow>( json ); } // Wire up type objects since they are not serialized var rockContext = new RockContext(); var workflowTypeService = new WorkflowTypeService( rockContext ); var activityTypeService = new WorkflowActivityTypeService( rockContext ); var actionTypeService = new WorkflowActionTypeService( rockContext ); Workflow.WorkflowType = workflowTypeService.Get( Workflow.WorkflowTypeId ); foreach(var activity in Workflow.Activities) { activity.ActivityType = activityTypeService.Get( activity.ActivityTypeId ); foreach(var action in activity.Actions) { action.ActionType = actionTypeService.Get( action.ActionTypeId ); } } // Add new log entries since they are not serialized LogEntries = ViewState["LogEntries"] as List<string>; if ( LogEntries == null ) { LogEntries = new List<string>(); } LogEntries.ForEach( l => Workflow.AddLogEntry( l ) ); ExpandedActivities = ViewState["ExpandedActivities"] as List<Guid>; if (ExpandedActivities == null) { ExpandedActivities = new List<Guid>(); } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click( object sender, EventArgs e ) { ParseControls( true ); var rockContext = new RockContext(); var service = new WorkflowTypeService( rockContext ); WorkflowType workflowType = null; int? workflowTypeId = hfWorkflowTypeId.Value.AsIntegerOrNull(); if ( workflowTypeId.HasValue ) { workflowType = service.Get( workflowTypeId.Value ); } if ( workflowType == null ) { workflowType = new WorkflowType(); } var validationErrors = new List<string>(); // check for unique prefix string prefix = tbNumberPrefix.UntrimmedText; if ( !string.IsNullOrWhiteSpace( prefix ) && prefix.ToUpper() != ( workflowType.WorkflowIdPrefix ?? string.Empty ).ToUpper() ) { if ( service.Queryable().AsNoTracking() .Any( w => w.Id != workflowType.Id && w.WorkflowIdPrefix == prefix ) ) { validationErrors.Add( "Workflow Number Prefix is already being used by another workflow type. Please use a unique prefix." ); } else { workflowType.WorkflowIdPrefix = prefix; } } else { workflowType.WorkflowIdPrefix = prefix; } workflowType.IsActive = cbIsActive.Checked; workflowType.Name = tbName.Text; workflowType.Description = tbDescription.Text; workflowType.CategoryId = cpCategory.SelectedValueAsInt(); workflowType.WorkTerm = tbWorkTerm.Text; workflowType.ModifiedByPersonAliasId = CurrentPersonAliasId; workflowType.ModifiedDateTime = RockDateTime.Now; int? mins = tbProcessingInterval.Text.AsIntegerOrNull(); if ( mins.HasValue ) { workflowType.ProcessingIntervalSeconds = mins.Value * 60; } else { workflowType.ProcessingIntervalSeconds = null; } workflowType.IsPersisted = cbIsPersisted.Checked; workflowType.LoggingLevel = ddlLoggingLevel.SelectedValueAsEnum<WorkflowLoggingLevel>(); workflowType.IconCssClass = tbIconCssClass.Text; workflowType.SummaryViewText = ceSummaryViewText.Text; workflowType.NoActionMessage = ceNoActionMessage.Text; if ( validationErrors.Any() ) { nbValidationError.Text = string.Format( "Please Correct the Following<ul><li>{0}</li></ul>", validationErrors.AsDelimited( "</li><li>" ) ); nbValidationError.Visible = true; return; } if ( !Page.IsValid || !workflowType.IsValid ) { return; } foreach(var activityType in ActivityTypesState) { if (!activityType.IsValid) { return; } foreach(var actionType in activityType.ActionTypes) { if ( !actionType.IsValid ) { return; } } } rockContext.WrapTransaction( () => { // Save the entity field changes to workflow type if ( workflowType.Id.Equals( 0 ) ) { service.Add( workflowType ); } rockContext.SaveChanges(); // Save the workflow type attributes SaveAttributes( new Workflow().TypeId, "WorkflowTypeId", workflowType.Id.ToString(), AttributesState, rockContext ); WorkflowActivityTypeService workflowActivityTypeService = new WorkflowActivityTypeService( rockContext ); WorkflowActivityService workflowActivityService = new WorkflowActivityService( rockContext ); WorkflowActionService workflowActionService = new WorkflowActionService( rockContext ); WorkflowActionTypeService workflowActionTypeService = new WorkflowActionTypeService( rockContext ); WorkflowActionFormService workflowFormService = new WorkflowActionFormService( rockContext ); WorkflowActionFormAttributeService workflowFormAttributeService = new WorkflowActionFormAttributeService( rockContext ); // delete WorkflowActionTypes that aren't assigned in the UI anymore List<WorkflowActionType> actionTypesInDB = workflowActionTypeService.Queryable().Where( a => a.ActivityType.WorkflowTypeId.Equals( workflowType.Id ) ).ToList(); List<WorkflowActionType> actionTypesInUI = new List<WorkflowActionType>(); foreach ( var workflowActivity in ActivityTypesState ) { foreach ( var workflowAction in workflowActivity.ActionTypes ) { actionTypesInUI.Add( workflowAction ); } } var deletedActionTypes = from actionType in actionTypesInDB where !actionTypesInUI.Select( u => u.Guid ).Contains( actionType.Guid ) select actionType; foreach ( var actionType in deletedActionTypes.ToList() ) { if ( actionType.WorkflowForm != null ) { workflowFormService.Delete( actionType.WorkflowForm ); } // Delete any workflow actions of this type int loopCounter = 0; foreach ( var action in workflowActionService.Queryable().Where( a => a.ActionTypeId == actionType.Id ) ) { workflowActionService.Delete( action ); loopCounter++; if ( loopCounter > 100 ) { rockContext.SaveChanges(); loopCounter = 0; } } rockContext.SaveChanges(); workflowActionTypeService.Delete( actionType ); } rockContext.SaveChanges(); // delete WorkflowActivityTypes that aren't assigned in the UI anymore List<WorkflowActivityType> activityTypesInDB = workflowActivityTypeService.Queryable().Where( a => a.WorkflowTypeId.Equals( workflowType.Id ) ).ToList(); var deletedActivityTypes = from activityType in activityTypesInDB where !ActivityTypesState.Select( u => u.Guid ).Contains( activityType.Guid ) select activityType; foreach ( var activityType in deletedActivityTypes.ToList() ) { // Delete any workflow activities of this type int loopCounter = 0; foreach ( var activity in workflowActivityService.Queryable().Where( a => a.ActivityTypeId == activityType.Id ) ) { workflowActivityService.Delete( activity ); loopCounter++; if ( loopCounter > 100 ) { rockContext.SaveChanges(); loopCounter = 0; } } rockContext.SaveChanges(); workflowActivityTypeService.Delete( activityType ); } rockContext.SaveChanges(); // add or update WorkflowActivityTypes(and Actions) that are assigned in the UI int workflowActivityTypeOrder = 0; foreach ( var editorWorkflowActivityType in ActivityTypesState ) { // Add or Update the activity type WorkflowActivityType workflowActivityType = workflowType.ActivityTypes.FirstOrDefault( a => a.Guid.Equals( editorWorkflowActivityType.Guid ) ); if ( workflowActivityType == null ) { workflowActivityType = new WorkflowActivityType(); workflowActivityType.Guid = editorWorkflowActivityType.Guid; workflowType.ActivityTypes.Add( workflowActivityType ); } workflowActivityType.IsActive = editorWorkflowActivityType.IsActive; workflowActivityType.Name = editorWorkflowActivityType.Name; workflowActivityType.Description = editorWorkflowActivityType.Description; workflowActivityType.IsActivatedWithWorkflow = editorWorkflowActivityType.IsActivatedWithWorkflow; workflowActivityType.Order = workflowActivityTypeOrder++; // Save Activity Type rockContext.SaveChanges(); // Save ActivityType Attributes if ( ActivityAttributesState.ContainsKey( workflowActivityType.Guid ) ) { SaveAttributes( new WorkflowActivity().TypeId, "ActivityTypeId", workflowActivityType.Id.ToString(), ActivityAttributesState[workflowActivityType.Guid], rockContext ); } // Because the SaveAttributes above may have flushed the cached entity attribute cache, and it would get loaded again with // a different context, manually reload the cache now with our context to prevent a database lock conflict (when database is // configured without snapshot isolation turned on) AttributeCache.LoadEntityAttributes( rockContext ); int workflowActionTypeOrder = 0; foreach ( var editorWorkflowActionType in editorWorkflowActivityType.ActionTypes ) { WorkflowActionType workflowActionType = workflowActivityType.ActionTypes.FirstOrDefault( a => a.Guid.Equals( editorWorkflowActionType.Guid ) ); if ( workflowActionType == null ) { // New action workflowActionType = new WorkflowActionType(); workflowActionType.Guid = editorWorkflowActionType.Guid; workflowActivityType.ActionTypes.Add( workflowActionType ); } workflowActionType.CriteriaAttributeGuid = editorWorkflowActionType.CriteriaAttributeGuid; workflowActionType.CriteriaComparisonType = editorWorkflowActionType.CriteriaComparisonType; workflowActionType.CriteriaValue = editorWorkflowActionType.CriteriaValue; workflowActionType.Name = editorWorkflowActionType.Name; workflowActionType.EntityTypeId = editorWorkflowActionType.EntityTypeId; workflowActionType.IsActionCompletedOnSuccess = editorWorkflowActionType.IsActionCompletedOnSuccess; workflowActionType.IsActivityCompletedOnSuccess = editorWorkflowActionType.IsActivityCompletedOnSuccess; workflowActionType.Attributes = editorWorkflowActionType.Attributes; workflowActionType.AttributeValues = editorWorkflowActionType.AttributeValues; workflowActionType.Order = workflowActionTypeOrder++; if ( workflowActionType.WorkflowForm != null && editorWorkflowActionType.WorkflowForm == null ) { // Form removed workflowFormService.Delete( workflowActionType.WorkflowForm ); workflowActionType.WorkflowForm = null; } if ( editorWorkflowActionType.WorkflowForm != null ) { if ( workflowActionType.WorkflowForm == null ) { workflowActionType.WorkflowForm = new WorkflowActionForm(); } workflowActionType.WorkflowForm.NotificationSystemEmailId = editorWorkflowActionType.WorkflowForm.NotificationSystemEmailId; workflowActionType.WorkflowForm.IncludeActionsInNotification = editorWorkflowActionType.WorkflowForm.IncludeActionsInNotification; workflowActionType.WorkflowForm.AllowNotes = editorWorkflowActionType.WorkflowForm.AllowNotes; workflowActionType.WorkflowForm.Header = editorWorkflowActionType.WorkflowForm.Header; workflowActionType.WorkflowForm.Footer = editorWorkflowActionType.WorkflowForm.Footer; workflowActionType.WorkflowForm.Actions = editorWorkflowActionType.WorkflowForm.Actions; workflowActionType.WorkflowForm.ActionAttributeGuid = editorWorkflowActionType.WorkflowForm.ActionAttributeGuid; var editorGuids = editorWorkflowActionType.WorkflowForm.FormAttributes .Select( a => a.Attribute.Guid ) .ToList(); foreach ( var formAttribute in workflowActionType.WorkflowForm.FormAttributes .Where( a => !editorGuids.Contains( a.Attribute.Guid ) ).ToList() ) { workflowFormAttributeService.Delete( formAttribute ); } int attributeOrder = 0; foreach ( var editorAttribute in editorWorkflowActionType.WorkflowForm.FormAttributes.OrderBy( a => a.Order ) ) { int attributeId = AttributeCache.Read( editorAttribute.Attribute.Guid, rockContext ).Id; var formAttribute = workflowActionType.WorkflowForm.FormAttributes .Where( a => a.AttributeId == attributeId ) .FirstOrDefault(); if ( formAttribute == null ) { formAttribute = new WorkflowActionFormAttribute(); formAttribute.Guid = editorAttribute.Guid; formAttribute.AttributeId = attributeId; workflowActionType.WorkflowForm.FormAttributes.Add( formAttribute ); } formAttribute.Order = attributeOrder++; formAttribute.IsVisible = editorAttribute.IsVisible; formAttribute.IsReadOnly = editorAttribute.IsReadOnly; formAttribute.IsRequired = editorAttribute.IsRequired; formAttribute.HideLabel = editorAttribute.HideLabel; formAttribute.PreHtml = editorAttribute.PreHtml; formAttribute.PostHtml = editorAttribute.PostHtml; } } } } rockContext.SaveChanges(); foreach ( var activityType in workflowType.ActivityTypes ) { foreach ( var workflowActionType in activityType.ActionTypes ) { workflowActionType.SaveAttributeValues( rockContext ); } } } ); var qryParams = new Dictionary<string, string>(); qryParams["workflowTypeId"] = workflowType.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); }