/// <summary> /// Gets the workflow attributes. /// </summary> /// <param name="workflowTypeId">The workflow type identifier.</param> /// <returns></returns> private List <EntityField> GetWorkflowAttributes(int?workflowTypeId) { List <EntityField> entityAttributeFields = new List <EntityField>(); if (workflowTypeId.HasValue) { var fakeWorkflow = new Rock.Model.Workflow { WorkflowTypeId = workflowTypeId.Value }; Rock.Attribute.Helper.LoadAttributes(fakeWorkflow); var attributeList = fakeWorkflow.Attributes.Select(a => a.Value).ToList(); EntityHelper.AddEntityFieldsForAttributeList(entityAttributeFields, attributeList); } int index = 0; var sortedFields = new List <EntityField>(); foreach (var entityProperty in entityAttributeFields.OrderBy(p => p.TitleWithoutQualifier).ThenBy(p => p.Name)) { entityProperty.Index = index; index++; sortedFields.Add(entityProperty); } return(sortedFields); }
private void GetState() { if (Session["CheckInKioskId"] != null) { CurrentKioskId = (int)Session["CheckInKioskId"]; } if (Session["CheckInGroupTypeIds"] != null) { CurrentGroupTypeIds = Session["CheckInGroupTypeIds"] as List <int>; } if (Session["CheckInState"] != null) { CurrentCheckInState = Session["CheckInState"] as CheckInState; } if (Session["CheckInWorkflow"] != null) { CurrentWorkflow = Session["CheckInWorkflow"] as Rock.Model.Workflow; } if (CurrentCheckInState == null && CurrentKioskId.HasValue) { CurrentCheckInState = new CheckInState(CurrentKioskId.Value, CurrentGroupTypeIds); } }
/// <summary> /// Cancels the check-in. /// </summary> protected void CancelCheckin() { CurrentWorkflow = null; CurrentCheckInState = null; SaveState(); NavigateToHomePage(); }
/// <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 workflowService = new WorkflowService(rockContext); var reference = GetAttributeValue(action, "WorkflowReference", true); Rock.Model.Workflow workflow = null; if (reference.AsGuidOrNull() != null) { var referenceGuid = reference.AsGuid(); workflow = new WorkflowService(rockContext).Queryable() .Where(w => w.Guid == referenceGuid) .FirstOrDefault(); } else if (reference.AsIntegerOrNull() != null) { var referenceInt = reference.AsInteger(); workflow = new WorkflowService(rockContext).Queryable() .Where(w => w.Id == referenceInt) .FirstOrDefault(); } else { action.AddLogEntry("Invalid Workflow Property", true); return(false); } workflowService.Process(workflow, out errorMessages); return(true); }
/// <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> /// Saves the attribute value. /// </summary> /// <param name="workflow">The workflow.</param> /// <param name="key">The key.</param> /// <param name="value">The value.</param> /// <param name="fieldType">Type of the field.</param> /// <param name="rockContext">The rock context.</param> /// <param name="qualifiers">The qualifiers.</param> /// <returns></returns> private static bool SaveAttributeValue(Rock.Model.Workflow workflow, string key, string value, FieldTypeCache fieldType, RockContext rockContext, Dictionary <string, string> qualifiers = null) { bool createdNewAttribute = false; if (workflow.Attributes.ContainsKey(key)) { workflow.SetAttributeValue(key, value); } else { // Read the attribute var attributeService = new AttributeService(rockContext); var attribute = attributeService .Get(workflow.TypeId, "WorkflowTypeId", workflow.WorkflowTypeId.ToString()) .Where(a => a.Key == key) .FirstOrDefault(); // If workflow attribute doesn't exist, create it // ( should only happen first time a background check is processed for given workflow type) if (attribute == null) { attribute = new Rock.Model.Attribute(); attribute.EntityTypeId = workflow.TypeId; attribute.EntityTypeQualifierColumn = "WorkflowTypeId"; attribute.EntityTypeQualifierValue = workflow.WorkflowTypeId.ToString(); attribute.Name = key.SplitCase(); attribute.Key = key; attribute.FieldTypeId = fieldType.Id; attributeService.Add(attribute); if (qualifiers != null) { foreach (var keyVal in qualifiers) { var qualifier = new Rock.Model.AttributeQualifier(); qualifier.Key = keyVal.Key; qualifier.Value = keyVal.Value; attribute.AttributeQualifiers.Add(qualifier); } } createdNewAttribute = true; } // Set the value for this action's instance to the current time var attributeValue = new Rock.Model.AttributeValue(); attributeValue.Attribute = attribute; attributeValue.EntityId = workflow.Id; attributeValue.Value = value; new AttributeValueService(rockContext).Add(attributeValue); } return(createdNewAttribute); }
/// <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 workflowActivityGuid = action.GetWorklowAttributeValue(GetAttributeValue(action, "Activity").AsGuid()).AsGuid(); if (workflowActivityGuid.IsEmpty()) { action.AddLogEntry("Invalid Activity Property", true); return(false); } var reference = GetAttributeValue(action, "WorkflowReference", true); Rock.Model.Workflow workflow = null; if (reference.AsGuidOrNull() != null) { var referenceGuid = reference.AsGuid(); workflow = new WorkflowService(rockContext).Queryable() .Where(w => w.Guid == referenceGuid) .FirstOrDefault(); } else if (reference.AsIntegerOrNull() != null) { var referenceInt = reference.AsInteger(); workflow = new WorkflowService(rockContext).Queryable() .Where(w => w.Id == referenceInt) .FirstOrDefault(); } else { action.AddLogEntry("Invalid Workflow Property", true); return(false); } var activityType = new WorkflowActivityTypeService(rockContext).Queryable() .Where(a => a.Guid.Equals(workflowActivityGuid)).FirstOrDefault(); if (activityType == null) { action.AddLogEntry("Invalid Activity Property", true); return(false); } WorkflowActivity.Activate(activityType, workflow); action.AddLogEntry(string.Format("Activated new '{0}' activity", activityType.ToString())); return(true); }
/// <summary> /// Gets the PersonEntryFamilyAttribute from either the WorkflowActionForm or WorkflowType.WorkflowFormBuilderTemplate /// </summary> /// <param name="workflow">The workflow</param> /// <returns></returns> public AttributeCache GetPersonEntryFamilyAttribute(Rock.Model.Workflow workflow) { var workflowType = workflow?.WorkflowTypeCache; if (workflowType?.FormBuilderTemplate != null) { return(workflow.Attributes.GetValueOrNull("Family")); } else if (this.PersonEntryFamilyAttributeGuid.HasValue) { return(AttributeCache.Get(this.PersonEntryFamilyAttributeGuid.Value)); } else { return(null); } }
private void PersistWorkflow(Rock.Model.Workflow workflow) { if (workflow.Id == 0) { var workflowService = new WorkflowService(_rockContext); workflowService.Add(workflow); } _rockContext.WrapTransaction(() => { _rockContext.SaveChanges(); workflow.SaveAttributeValues(_rockContext); foreach (var activity in workflow.Activities) { activity.SaveAttributeValues(_rockContext); } }); }
/// <summary> /// Saves the results. /// </summary> /// <param name="xResult">The x result.</param> /// <param name="workflow">The workflow.</param> /// <param name="rockContext">The rock context.</param> public static void SaveResults(XDocument xResult, Rock.Model.Workflow workflow, RockContext rockContext) { var xOrderDetail = xResult.Descendants("OrderDetail").FirstOrDefault(); if (xOrderDetail != null) { string status = (from o in xOrderDetail.Descendants("Status") select o.Value).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(status)) { // Request has been completed // Save the status SaveAttributeValue(workflow, "ReportStatus", status == "NO RECORD" ? "Pass" : "Review", FieldTypeCache.Read(Rock.SystemGuid.FieldType.SINGLE_SELECT.AsGuid()), rockContext, new Dictionary <string, string> { { "fieldtype", "ddl" }, { "values", "Pass,Fail,Review" } }); // Save the report link string reportLink = (from o in xResult.Descendants("ReportLink") select o.Value).FirstOrDefault(); SaveAttributeValue(workflow, "ReportLink", reportLink, FieldTypeCache.Read(Rock.SystemGuid.FieldType.URL_LINK.AsGuid()), rockContext); // Save the recommendation string recommendation = (from o in xResult.Descendants("Recommendation") select o.Value).FirstOrDefault(); SaveAttributeValue(workflow, "ReportRecommendation", recommendation, FieldTypeCache.Read(Rock.SystemGuid.FieldType.TEXT.AsGuid()), rockContext, new Dictionary <string, string> { { "ispassword", "false" } }); // Save the report Guid?binaryFileGuid = SaveFile(workflow.Attributes["Report"], reportLink, workflow.Id.ToString() + ".pdf"); if (binaryFileGuid.HasValue) { SaveAttributeValue(workflow, "Report", binaryFileGuid.Value.ToString(), FieldTypeCache.Read(Rock.SystemGuid.FieldType.BINARY_FILE.AsGuid()), rockContext, new Dictionary <string, string> { { "binaryFileType", "" } }); } } } }
private void SaveForProcessingLater(Rock.Model.Workflow newWorkflow, RockContext rockContext) { newWorkflow.IsPersisted = true; var service = new WorkflowService(rockContext); if (newWorkflow.Id == 0) { service.Add(newWorkflow); } rockContext.WrapTransaction(() => { rockContext.SaveChanges(); newWorkflow.SaveAttributeValues(rockContext); foreach (var activity in newWorkflow.Activities) { activity.SaveAttributeValues(rockContext); } }); }
/// <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>(); int workflowTypeId = 0; if (Int32.TryParse(GetAttributeValue("WorkflowTypeId"), out workflowTypeId)) { var workflowTypeService = new WorkflowTypeService(); var workflowType = workflowTypeService.Get(workflowTypeId); if (workflowType != null) { if (CurrentWorkflow == null) { CurrentWorkflow = Rock.Model.Workflow.Activate(workflowType, CurrentCheckInState.Kiosk.Device.Name); } var activityType = workflowType.ActivityTypes.Where(a => a.Name == activityName).FirstOrDefault(); if (activityType != null) { WorkflowActivity.Activate(activityType, CurrentWorkflow); if (CurrentWorkflow.Process(CurrentCheckInState, out errorMessages)) { return(true); } } else { errorMessages.Add(string.Format("Workflow type does not have a '{0}' activity type", activityName)); } } else { errorMessages.Add(string.Format("Invalid Workflow type Id", activityName)); } } return(false); }
private void BindAttributes() { // Parse the attribute filters AvailableAttributes = new List <AttributeCache>(); if (_workflowType != null) { int entityTypeId = new Rock.Model.Workflow().TypeId; string workflowQualifier = _workflowType.Id.ToString(); foreach (var attributeModel in new AttributeService(new RockContext()).Queryable() .Where(a => a.EntityTypeId == entityTypeId && a.IsGridColumn && a.EntityTypeQualifierColumn.Equals("WorkflowTypeId", StringComparison.OrdinalIgnoreCase) && a.EntityTypeQualifierValue.Equals(workflowQualifier)) .OrderByDescending(a => a.EntityTypeQualifierColumn) .ThenBy(a => a.Order) .ThenBy(a => a.Name)) { AvailableAttributes.Add(AttributeCache.Get(attributeModel)); } } }
private void CopyAttributes(Rock.Model.Workflow newWorkflow, Rock.Model.WorkflowActivity currentActivity, RockContext rockContext) { if (currentActivity.Attributes == null) { currentActivity.LoadAttributes(rockContext); } if (currentActivity.Workflow.Attributes == null) { currentActivity.Workflow.LoadAttributes(rockContext); } // Pass attributes from current Workflow to new Workflow. foreach (string key in currentActivity.Workflow.AttributeValues.Keys) { newWorkflow.SetAttributeValue(key, currentActivity.Workflow.GetAttributeValue(key)); } // Pass attributes from current Activity to new Workflow. foreach (string key in currentActivity.AttributeValues.Keys) { newWorkflow.SetAttributeValue(key, currentActivity.GetAttributeValue(key)); } }
/// <summary> /// Shows the detail. /// </summary> private void ShowDetail( int workflowId ) { var rockContext = new RockContext(); Workflow = new WorkflowService( rockContext ) .Queryable( "WorkflowType, Activities") .Where( w => w.Id == workflowId ) .FirstOrDefault(); if ( Workflow == null ) { pnlContent.Visible = false; return; } Workflow.LoadAttributes( rockContext ); foreach ( var activity in Workflow.Activities ) { activity.LoadAttributes(); } lReadOnlyTitle.Text = Workflow.Name.FormatAsHtmlTitle(); if ( Workflow.CompletedDateTime.HasValue ) { hlState.LabelType = LabelType.Default; hlState.Text = "Complete"; } else { hlState.LabelType = LabelType.Success; hlState.Text = "Active"; } hlType.Text = Workflow.WorkflowType.Name; ShowReadonlyDetails(); }
/// <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 ) { var rockContext = new RockContext(); var service = new WorkflowService( rockContext ); ParseControls( rockContext, true ); Workflow dbWorkflow = null; if ( Workflow != null ) { dbWorkflow = service.Get( Workflow.Id ); if ( dbWorkflow != null ) { if ( !dbWorkflow.CompletedDateTime.HasValue && Workflow.CompletedDateTime.HasValue ) { dbWorkflow.AddLogEntry( "Workflow Manually Completed." ); dbWorkflow.CompletedDateTime = Workflow.CompletedDateTime; } else if ( dbWorkflow.CompletedDateTime.HasValue && !Workflow.CompletedDateTime.HasValue ) { dbWorkflow.AddLogEntry( "Workflow Manually Re-Activated." ); dbWorkflow.CompletedDateTime = null; } if ( dbWorkflow.Name.Trim() != Workflow.Name.Trim() ) { dbWorkflow.AddLogEntry( string.Format( "Workflow name manually changed from '{0}' to '{0}'.", dbWorkflow.Name, tbName.Text ) ); dbWorkflow.Name = Workflow.Name; } if ( dbWorkflow.Status.Trim() != Workflow.Status.Trim() ) { dbWorkflow.AddLogEntry( string.Format( "Workflow status manually changed from '{0}' to '{0}'.", dbWorkflow.Status, tbStatus.Text ) ); dbWorkflow.Status = Workflow.Status; } if ( !dbWorkflow.InitiatorPersonAliasId.Equals(Workflow.InitiatorPersonAliasId)) { dbWorkflow.AddLogEntry( string.Format( "Workflow status manually changed from '{0}' to '{0}'.", dbWorkflow.InitiatorPersonAlias != null ? dbWorkflow.InitiatorPersonAlias.Person.FullName : "", Workflow.InitiatorPersonAlias != null ? Workflow.InitiatorPersonAlias.Person.FullName : "" ) ); dbWorkflow.InitiatorPersonAlias = Workflow.InitiatorPersonAlias; dbWorkflow.InitiatorPersonAliasId = Workflow.InitiatorPersonAliasId; } if ( !Page.IsValid || !dbWorkflow.IsValid ) { return; } foreach ( var activity in Workflow.Activities ) { if ( !activity.IsValid ) { return; } foreach ( var action in activity.Actions ) { if ( !action.IsValid ) { return; } } } rockContext.WrapTransaction( () => { rockContext.SaveChanges(); dbWorkflow.LoadAttributes( rockContext ); foreach ( var attributeValue in Workflow.AttributeValues ) { dbWorkflow.SetAttributeValue( attributeValue.Key, Workflow.GetAttributeValue( attributeValue.Key ) ); } dbWorkflow.SaveAttributeValues( rockContext ); WorkflowActivityService workflowActivityService = new WorkflowActivityService( rockContext ); WorkflowActionService workflowActionService = new WorkflowActionService( rockContext ); var activitiesInUi = new List<Guid>(); var actionsInUI = new List<Guid>(); foreach ( var activity in Workflow.Activities ) { activitiesInUi.Add( activity.Guid ); foreach ( var action in activity.Actions ) { actionsInUI.Add( action.Guid ); } } // delete WorkflowActions that were removed in the UI foreach ( var action in workflowActionService.Queryable() .Where( a => a.Activity.WorkflowId.Equals( dbWorkflow.Id ) && !actionsInUI.Contains( a.Guid ) ) ) { workflowActionService.Delete( action ); } // delete WorkflowActivities that aren't assigned in the UI anymore foreach ( var activity in workflowActivityService.Queryable() .Where( a => a.WorkflowId.Equals( dbWorkflow.Id ) && !activitiesInUi.Contains( a.Guid ) ) ) { workflowActivityService.Delete( activity ); } rockContext.SaveChanges(); // add or update WorkflowActivities(and Actions) that are assigned in the UI foreach ( var editorWorkflowActivity in Workflow.Activities ) { // Add or Update the activity type WorkflowActivity workflowActivity = dbWorkflow.Activities.FirstOrDefault( a => a.Guid.Equals( editorWorkflowActivity.Guid ) ); if ( workflowActivity == null ) { workflowActivity = new WorkflowActivity(); workflowActivity.ActivityTypeId = editorWorkflowActivity.ActivityTypeId; dbWorkflow.Activities.Add( workflowActivity ); } workflowActivity.AssignedPersonAliasId = editorWorkflowActivity.AssignedPersonAliasId; workflowActivity.AssignedGroupId = editorWorkflowActivity.AssignedGroupId; workflowActivity.ActivatedDateTime = editorWorkflowActivity.ActivatedDateTime; workflowActivity.LastProcessedDateTime = editorWorkflowActivity.LastProcessedDateTime; if ( !workflowActivity.CompletedDateTime.HasValue && editorWorkflowActivity.CompletedDateTime.HasValue ) { workflowActivity.AddLogEntry( "Activity Manually Completed." ); workflowActivity.CompletedDateTime = RockDateTime.Now; } if ( workflowActivity.CompletedDateTime.HasValue && !editorWorkflowActivity.CompletedDateTime.HasValue ) { workflowActivity.AddLogEntry( "Activity Manually Re-Activated." ); workflowActivity.CompletedDateTime = null; } // Save Activity Type rockContext.SaveChanges(); // Save ActivityType Attributes workflowActivity.LoadAttributes( rockContext ); foreach ( var attributeValue in editorWorkflowActivity.AttributeValues ) { workflowActivity.SetAttributeValue( attributeValue.Key, editorWorkflowActivity.GetAttributeValue( attributeValue.Key ) ); } workflowActivity.SaveAttributeValues( rockContext ); foreach ( var editorWorkflowAction in editorWorkflowActivity.Actions ) { WorkflowAction workflowAction = workflowActivity.Actions.FirstOrDefault( a => a.Guid.Equals( editorWorkflowAction.Guid ) ); if ( workflowAction == null ) { // New action workflowAction = new WorkflowAction(); workflowAction.ActionTypeId = editorWorkflowAction.ActionTypeId; workflowActivity.Actions.Add( workflowAction ); } workflowAction.LastProcessedDateTime = editorWorkflowAction.LastProcessedDateTime; workflowAction.FormAction = editorWorkflowAction.FormAction; if ( !workflowAction.CompletedDateTime.HasValue && editorWorkflowAction.CompletedDateTime.HasValue ) { workflowAction.AddLogEntry( "Action Manually Completed." ); workflowAction.CompletedDateTime = RockDateTime.Now; } if ( workflowAction.CompletedDateTime.HasValue && !editorWorkflowAction.CompletedDateTime.HasValue ) { workflowAction.AddLogEntry( "Action Manually Re-Activated." ); workflowAction.CompletedDateTime = null; } } // Save action updates rockContext.SaveChanges(); } } ); } Workflow = service .Queryable("WorkflowType,Activities.ActivityType,Activities.Actions.ActionType") .FirstOrDefault( w => w.Id == Workflow.Id ); var errorMessages = new List<string>(); service.Process( Workflow, out errorMessages ); } ShowReadonlyDetails(); }
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (_rockContext == null) { _rockContext = new RockContext(); } if (_workflowService == null) { _workflowService = new WorkflowService(_rockContext); } var paramWorkflowId = PageParameter("WorkflowId"); WorkflowId = paramWorkflowId.AsIntegerOrNull(); if (!WorkflowId.HasValue) { Guid guid = PageParameter("WorkflowGuid").AsGuid(); if (!guid.IsEmpty()) { _workflow = _workflowService.Queryable() .Where(w => w.Guid.Equals(guid)) .FirstOrDefault(); if (_workflow != null) { WorkflowId = _workflow.Id; } } } if (WorkflowId.HasValue) { if (_workflow == null) { _workflow = _workflowService.Queryable() .Where(w => w.Id == WorkflowId.Value) .FirstOrDefault(); } //------------------------------- if (_workflow != null) { _workflow.LoadAttributes(); } } if (_workflow != null) { if (_workflow.IsActive) { int personId = CurrentPerson != null ? CurrentPerson.Id : 0; foreach (var activity in _workflow.Activities .Where(a => a.IsActive && ( (!a.AssignedGroupId.HasValue && !a.AssignedPersonAliasId.HasValue) || (a.AssignedPersonAlias != null && a.AssignedPersonAlias.PersonId == personId) || (a.AssignedGroup != null && a.AssignedGroup.Members.Any(m => m.PersonId == personId)) ) ) .OrderBy(a => a.ActivityType.Order)) { if ((activity.ActivityType.IsAuthorized(Authorization.VIEW, CurrentPerson))) { foreach (var action in activity.ActiveActions) { if (action.ActionType.WorkflowForm != null && action.IsCriteriaValid) { _activity = activity; _activity.LoadAttributes(_rockContext); } } } } if (_activity != null) { var entryPage = _workflow.GetAttributeValue("EntryFormPage"); if (!String.IsNullOrEmpty(entryPage)) { var queryParams = new Dictionary <string, string>(); queryParams.Add("WorkflowTypeId", _activity.Workflow.WorkflowTypeId.ToString()); queryParams.Add("WorkflowId", _activity.WorkflowId.ToString()); var attrsToSend = GetAttributeValue("WorkflowAttributes"); if (!String.IsNullOrWhiteSpace(attrsToSend)) { foreach (var attr in attrsToSend.Split(',')) { var attrName = attr.Trim(); if (!String.IsNullOrEmpty(_activity.GetAttributeValue(attrName))) { queryParams.Add(attrName, _activity.GetAttributeValue(attrName)); } else if (!String.IsNullOrEmpty(_activity.Workflow.GetAttributeValue(attrName))) { queryParams.Add(attrName, _activity.Workflow.GetAttributeValue(attrName)); } } } var pageReference = new Rock.Web.PageReference(entryPage, queryParams); bool paramsDiffer = false; foreach (var pair in queryParams) { if (pair.Value != PageParameter(pair.Key)) { paramsDiffer = true; break; } } if (paramsDiffer || (pageReference.PageId != CurrentPageReference.PageId)) { Response.Redirect(pageReference.BuildUrl(), true); } } } } } }
/// <summary> /// Saves the results. /// </summary> /// <param name="xResult">The x result.</param> /// <param name="workflow">The workflow.</param> /// <param name="rockContext">The rock context.</param> /// <param name="saveResponse">if set to <c>true</c> [save response].</param> public static void SaveResults(XDocument xResult, Rock.Model.Workflow workflow, RockContext rockContext, bool saveResponse = true) { bool createdNewAttribute = false; var newRockContext = new RockContext(); var service = new BackgroundCheckService(newRockContext); var backgroundCheck = service.Queryable() .Where(c => c.WorkflowId.HasValue && c.WorkflowId.Value == workflow.Id) .FirstOrDefault(); if (backgroundCheck != null && saveResponse) { // Clear any SSN nodes before saving XML to record foreach (var xSSNElement in xResult.Descendants("SSN")) { xSSNElement.Value = "XXX-XX-XXXX"; } backgroundCheck.ResponseXml = backgroundCheck.ResponseXml + string.Format(@" Response XML ({0}): ------------------------ {1} ", RockDateTime.Now.ToString(), xResult.ToString()); } var xOrderXML = xResult.Elements("OrderXML").FirstOrDefault(); if (xOrderXML != null) { var xOrder = xOrderXML.Elements("Order").FirstOrDefault(); if (xOrder != null) { bool resultFound = false; // Find any order details with a status element string reportStatus = "Pass"; foreach (var xOrderDetail in xOrder.Elements("OrderDetail")) { var xStatus = xOrderDetail.Elements("Status").FirstOrDefault(); if (xStatus != null) { resultFound = true; if (xStatus.Value != "NO RECORD") { reportStatus = "Review"; break; } } } if (resultFound) { // If no records found, still double-check for any alerts if (reportStatus != "Review") { var xAlerts = xOrder.Elements("Alerts").FirstOrDefault(); if (xAlerts != null) { if (xAlerts.Elements("OrderId").Any()) { reportStatus = "Review"; } } } // Save the recommendation string recommendation = (from o in xOrder.Elements("Recommendation") select o.Value).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(recommendation)) { if (SaveAttributeValue(workflow, "ReportRecommendation", recommendation, FieldTypeCache.Read(Rock.SystemGuid.FieldType.TEXT.AsGuid()), rockContext, new Dictionary <string, string> { { "ispassword", "false" } })) { createdNewAttribute = true; } } // Save the report link Guid? binaryFileGuid = null; string reportLink = (from o in xOrder.Elements("ReportLink") select o.Value).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(reportLink)) { if (SaveAttributeValue(workflow, "ReportLink", reportLink, FieldTypeCache.Read(Rock.SystemGuid.FieldType.URL_LINK.AsGuid()), rockContext)) { createdNewAttribute = true; } // Save the report binaryFileGuid = SaveFile(workflow.Attributes["Report"], reportLink, workflow.Id.ToString() + ".pdf"); if (binaryFileGuid.HasValue) { if (SaveAttributeValue(workflow, "Report", binaryFileGuid.Value.ToString(), FieldTypeCache.Read(Rock.SystemGuid.FieldType.BINARY_FILE.AsGuid()), rockContext, new Dictionary <string, string> { { "binaryFileType", "" } })) { createdNewAttribute = true; } } } // Save the status if (SaveAttributeValue(workflow, "ReportStatus", reportStatus, FieldTypeCache.Read(Rock.SystemGuid.FieldType.SINGLE_SELECT.AsGuid()), rockContext, new Dictionary <string, string> { { "fieldtype", "ddl" }, { "values", "Pass,Fail,Review" } })) { createdNewAttribute = true; } // Update the background check file if (backgroundCheck != null) { backgroundCheck.ResponseDate = RockDateTime.Now; backgroundCheck.RecordFound = reportStatus == "Review"; if (binaryFileGuid.HasValue) { var binaryFile = new BinaryFileService(newRockContext).Get(binaryFileGuid.Value); if (binaryFile != null) { backgroundCheck.ResponseDocumentId = binaryFile.Id; } } } } } } newRockContext.SaveChanges(); if (createdNewAttribute) { AttributeCache.FlushEntityAttributes(); } }
/// <summary> /// Shows the detail. /// </summary> private void ShowDetail( int workflowId ) { var rockContext = new RockContext(); Workflow = new WorkflowService( rockContext ) .Queryable( "WorkflowType, Activities") .Where( w => w.Id == workflowId ) .FirstOrDefault(); if ( Workflow == null ) { pnlContent.Visible = false; // hide the panel drawer that show created and last modified dates pdAuditDetails.Visible = false; return; } pdAuditDetails.SetEntity( Workflow, ResolveRockUrl( "~" ) ); _canEdit = UserCanEdit || Workflow.IsAuthorized( Rock.Security.Authorization.EDIT, CurrentPerson ); Workflow.LoadAttributes( rockContext ); foreach ( var activity in Workflow.Activities ) { activity.LoadAttributes(); } lReadOnlyTitle.Text = Workflow.Name.FormatAsHtmlTitle(); if ( Workflow.CompletedDateTime.HasValue ) { hlState.LabelType = LabelType.Default; hlState.Text = "Complete"; } else { hlState.LabelType = LabelType.Success; hlState.Text = "Active"; } hlType.Text = Workflow.WorkflowType.Name; hlblWorkflowId.Text = Workflow.WorkflowId; ShowReadonlyDetails(); }
/// <summary> /// Gets the state. /// </summary> private void GetState() { if ( Session["CurrentTheme"] != null ) { CurrentTheme = Session["CurrentTheme"].ToString(); } if ( Session["CheckInKioskId"] != null ) { CurrentKioskId = (int)Session["CheckInKioskId"]; } if ( Session["CheckinTypeId"] != null ) { CurrentCheckinTypeId = (int)Session["CheckinTypeId"]; } if ( Session["CheckInGroupTypeIds"] != null ) { CurrentGroupTypeIds = Session["CheckInGroupTypeIds"] as List<int>; } if ( Session["CheckInState"] != null ) { CurrentCheckInState = Session["CheckInState"] as CheckInState; } if ( Session["CheckInWorkflow"] != null ) { CurrentWorkflow = Session["CheckInWorkflow"] as Rock.Model.Workflow; } if ( CurrentCheckInState == null && CurrentKioskId.HasValue ) { CurrentCheckInState = new CheckInState( CurrentKioskId.Value, CurrentCheckinTypeId, CurrentGroupTypeIds ); } }
/// <summary> /// Shows the detail. /// </summary> private void ShowDetail() { var rockContext = new RockContext(); int? workflowId = PageParameter( "workflowId" ).AsIntegerOrNull(); if ( workflowId.HasValue ) { Workflow = new WorkflowService( rockContext ) .Queryable( "WorkflowType, Activities") .Where( w => w.Id == workflowId.Value ) .FirstOrDefault(); } if ( Workflow == null ) { pnlDetails.Visible = false; return; } if ( IsUserAuthorized( Authorization.VIEW ) && Workflow.IsAuthorized( Authorization.VIEW, CurrentPerson ) ) { pnlDetails.Visible = true; tbName.Visible = _canEdit; ppInitiator.Visible = _canEdit; tbStatus.Visible = _canEdit; lName.Visible = !_canEdit; lInitiator.Visible = !_canEdit; lStatus.Visible = !_canEdit; cbIsCompleted.Enabled = _canEdit; ddlActivateNewActivity.Visible = _canEdit; btnSave.Visible = _canEdit; btnCancel.Visible = _canEdit; if ( _canEdit ) { ddlActivateNewActivity.Items.Clear(); ddlActivateNewActivity.Items.Add( new ListItem( "Activate New Activity", "0" ) ); foreach ( var activityType in Workflow.WorkflowType.ActivityTypes.OrderBy( a => a.Order ) ) { ddlActivateNewActivity.Items.Add( new ListItem( activityType.Name, activityType.Id.ToString() ) ); } } ExpandedActivities = new List<Guid>(); Workflow.LoadAttributes( rockContext ); foreach ( var activity in Workflow.Activities ) { activity.LoadAttributes(); } BuildControls( true ); BindLog(); } else { nbNotAuthorized.Visible = true; pnlDetails.Visible = false; } }
/// <summary> /// Renders the specified context. /// </summary> /// <param name="context">The context.</param> /// <param name="result">The result.</param> public override void Render(Context context, TextWriter result) { // first ensure that entity commands are allowed in the context if (!this.IsAuthorized(context)) { result.Write(string.Format(RockLavaBlockBase.NotAuthorizedMessage, this.Name)); base.Render(context, result); return; } var attributes = new Dictionary <string, string>(); string parmWorkflowType = null; string parmWorkflowName = null; string parmWorkflowId = null; string parmActivityType = null; /* Parse the markup text to pull out configuration parameters. */ var parms = ParseMarkup(_markup, context); foreach (var p in parms) { if (p.Key.ToLower() == "workflowtype") { parmWorkflowType = p.Value; } else if (p.Key.ToLower() == "workflowname") { parmWorkflowName = p.Value; } else if (p.Key.ToLower() == "workflowid") { parmWorkflowId = p.Value; } else if (p.Key.ToLower() == "activitytype") { parmActivityType = p.Value; } else { attributes.AddOrReplace(p.Key, p.Value); } } /* Process inside a new stack level so our own created variables do not * persist throughout the rest of the workflow. */ context.Stack(() => { using (var rockContext = new RockContext()) { WorkflowService workflowService = new WorkflowService(rockContext); Rock.Model.Workflow workflow = null; WorkflowActivity activity = null; /* They provided a WorkflowType, so we need to kick off a new workflow. */ if (parmWorkflowType != null) { string type = parmWorkflowType; string name = parmWorkflowName ?? string.Empty; WorkflowTypeCache workflowType = null; /* Get the type of workflow */ if (type.AsGuidOrNull() != null) { workflowType = WorkflowTypeCache.Read(type.AsGuid()); } else if (type.AsIntegerOrNull() != null) { workflowType = WorkflowTypeCache.Read(type.AsInteger()); } /* Try to activate the workflow */ if (workflowType != null) { workflow = Rock.Model.Workflow.Activate(workflowType, parmWorkflowName); /* Set any workflow attributes that were specified. */ foreach (var attr in attributes) { if (workflow.Attributes.ContainsKey(attr.Key)) { workflow.SetAttributeValue(attr.Key, attr.Value.ToString()); } } if (workflow != null) { List <string> errorMessages; workflowService.Process(workflow, out errorMessages); if (errorMessages.Any()) { context["Error"] = string.Join("; ", errorMessages.ToArray()); } context["Workflow"] = workflow; } else { context["Error"] = "Could not activate workflow."; } } else { context["Error"] = "Workflow type not found."; } } /* They instead provided a WorkflowId, so we are working with an existing Workflow. */ else if (parmWorkflowId != null) { string id = parmWorkflowId.ToString(); /* Get the workflow */ if (id.AsGuidOrNull() != null) { workflow = workflowService.Get(id.AsGuid()); } else if (id.AsIntegerOrNull() != null) { workflow = workflowService.Get(id.AsInteger()); } if (workflow != null) { if (workflow.CompletedDateTime == null) { /* Currently we cannot activate an activity in a workflow that is currently * being processed. The workflow is held in-memory so the activity we would * activate would not show up for the processor and probably never run. */ if (!workflow.IsProcessing) { bool hasError = false; /* If they provided an ActivityType parameter then we need to activate * a new activity in the workflow. */ if (parmActivityType != null) { string type = parmActivityType.ToString(); WorkflowActivityTypeCache activityType = null; /* Get the type of activity */ if (type.AsGuidOrNull() != null) { activityType = WorkflowActivityTypeCache.Read(type.AsGuid()); } else if (type.AsIntegerOrNull() != null) { activityType = WorkflowActivityTypeCache.Read(type.AsInteger()); } if (activityType != null) { activity = WorkflowActivity.Activate(activityType, workflow); /* Set any workflow attributes that were specified. */ foreach (var attr in attributes) { if (activity.Attributes.ContainsKey(attr.Key)) { activity.SetAttributeValue(attr.Key, attr.Value.ToString()); } } } else { context["Error"] = "Activity type was not found."; hasError = true; } } /* Process the existing Workflow. */ if (!hasError) { List <string> errorMessages; workflowService.Process(workflow, out errorMessages); if (errorMessages.Any()) { context["Error"] = string.Join("; ", errorMessages.ToArray()); } context["Workflow"] = workflow; context["Activity"] = activity; } } else { context["Error"] = "Cannot activate activity on workflow that is currently being processed."; } } else { context["Error"] = "Workflow has already been completed."; } } else { context["Error"] = "Workflow not found."; } } else { context["Error"] = "Must specify one of WorkflowType or WorkflowId."; } RenderAll(NodeList, context, result); } }); }
/// <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 ( IsOverride ) { 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> /// Sends a background request to Trak-1 /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="workflow">The Workflow initiating the request.</param> /// <param name="personAttribute">The person attribute.</param> /// <param name="ssnAttribute">The SSN attribute.</param> /// <param name="requestTypeAttribute">The request type attribute.</param> /// <param name="billingCodeAttribute">The billing code attribute.</param> /// <param name="errorMessages">The error messages.</param> /// <returns> /// True/False value of whether the request was successfully sent or not /// </returns> /// <exception cref="System.NotImplementedException"></exception> /// <remarks> /// Note: If the associated workflow type does not have attributes with the following keys, they /// will automatically be added to the workflow type configuration in order to store the results /// of the background check request /// RequestStatus: The request status returned by request /// RequestMessage: Any error messages returned by request /// ReportStatus: The report status returned /// ReportLink: The location of the background report on server /// ReportRecommendation: Recomendataion /// Report (BinaryFile): The downloaded background report /// </remarks> public override bool SendRequest(RockContext rockContext, Rock.Model.Workflow workflow, AttributeCache personAttribute, AttributeCache ssnAttribute, AttributeCache requestTypeAttribute, AttributeCache billingCodeAttribute, out List <string> errorMessages) { errorMessages = new List <string>(); try { // Check to make sure workflow is not null if (workflow == null) { errorMessages.Add("Trak-1 background check provider requires a valid workflow."); return(false); } // Get the person that the request is for Person person = null; if (personAttribute != null) { Guid?personAliasGuid = workflow.GetAttributeValue(personAttribute.Key).AsGuidOrNull(); if (personAliasGuid.HasValue) { person = new PersonAliasService(rockContext).Queryable() .Where(p => p.Guid.Equals(personAliasGuid.Value)) .Select(p => p.Person) .FirstOrDefault(); person.LoadAttributes(rockContext); } } if (person == null) { errorMessages.Add("Trak-1 background check provider requires the workflow to have a 'Person' attribute that contains the person who the background check is for."); return(false); } //Get required fields from workflow var packageList = GetPackageList(); var packageName = workflow.GetAttributeValue(requestTypeAttribute.Key); // If this is a defined value, fetch the value if (requestTypeAttribute.FieldType.Guid.ToString().ToUpper() == Rock.SystemGuid.FieldType.DEFINED_VALUE) { packageName = DefinedValueCache.Get(packageName).Value; } var package = packageList.Where(p => p.PackageName == packageName).FirstOrDefault(); if (package == null) { errorMessages.Add("Package name not valid"); return(false); } var requiredFields = package.Components.SelectMany(c => c.RequiredFields).ToList(); var requiredFieldsDict = new Dictionary <string, string>(); foreach (var field in requiredFields) { if (!workflow.Attributes.ContainsKey(field.Name)) { errorMessages.Add("Workflow does not contain attribute for required field " + field.Name); return(false); } requiredFieldsDict[field.Name] = workflow.GetAttributeValue(field.Name); } //Generate Request var authentication = new Trak1Authentication { UserName = GetAttributeValue("UserName"), SubscriberCode = Encryption.DecryptString(GetAttributeValue("SubscriberCode")), CompanyCode = Encryption.DecryptString(GetAttributeValue("CompanyCode")), BranchName = "Main" }; var ssn = ""; if (ssnAttribute != null) { ssn = Rock.Field.Types.SSNFieldType.UnencryptAndClean(workflow.GetAttributeValue(ssnAttribute.Key)); if (!string.IsNullOrWhiteSpace(ssn) && ssn.Length == 9) { ssn = ssn.Insert(5, "-").Insert(3, "-"); } } Location homeLocation = null; var homeAddressDv = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME); foreach (var family in person.GetFamilies(rockContext)) { var loc = family.GroupLocations .Where(l => l.GroupLocationTypeValueId == homeAddressDv.Id) .Select(l => l.Location) .FirstOrDefault(); if (loc != null) { homeLocation = loc; } } if (homeLocation == null) { errorMessages.Add("A valid home location to submit a Trak-1 background check."); return(false); } var applicant = new Trak1Applicant { SSN = ssn, FirstName = person.FirstName, MiddleName = person.MiddleName, LastName = person.LastName, DateOfBirth = (person.BirthDate ?? new DateTime()).ToString("yyyy-MM-dd"), Address1 = homeLocation.Street1, Address2 = homeLocation.Street2, City = homeLocation.City, State = homeLocation.State, Zip = homeLocation.PostalCode, RequiredFields = requiredFieldsDict }; var request = new Trak1Request { Authentication = authentication, Applicant = applicant, PackageName = packageName }; var content = JsonConvert.SerializeObject(request); Trak1Response response = null; using (var client = new HttpClient(new HttpClientHandler())) { client.BaseAddress = new Uri(GetAttributeValue("RequestURL")); var clientResponse = client.PostAsync("", new StringContent(content, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result; response = JsonConvert.DeserializeObject <Trak1Response>(clientResponse); } if (!string.IsNullOrWhiteSpace(response.Error?.Message)) { errorMessages.Add(response.Error.Message); return(false); } var transactionId = response.TransactionId; int?personAliasId = person.PrimaryAliasId; if (personAliasId.HasValue) { // Create a background check file using (var newRockContext = new RockContext()) { var backgroundCheckService = new BackgroundCheckService(newRockContext); var backgroundCheck = backgroundCheckService.Queryable() .Where(c => c.WorkflowId.HasValue && c.WorkflowId.Value == workflow.Id) .FirstOrDefault(); if (backgroundCheck == null) { backgroundCheck = new Rock.Model.BackgroundCheck(); backgroundCheck.PersonAliasId = personAliasId.Value; backgroundCheck.WorkflowId = workflow.Id; backgroundCheckService.Add(backgroundCheck); } backgroundCheck.RequestDate = RockDateTime.Now; backgroundCheck.RequestId = transactionId.ToString(); backgroundCheck.PackageName = request.PackageName; newRockContext.SaveChanges(); } } return(true); } catch (Exception ex) { ExceptionLogService.LogException(ex, null); errorMessages.Add(ex.Message); return(false); } }
/// <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>(); int workflowTypeId = 0; if ( Int32.TryParse( GetAttributeValue( "WorkflowTypeId" ), out workflowTypeId ) ) { var workflowTypeService = new WorkflowTypeService(); var workflowType = workflowTypeService.Get( workflowTypeId ); if ( workflowType != null ) { if ( CurrentWorkflow == null ) { CurrentWorkflow = Rock.Model.Workflow.Activate( workflowType, CurrentCheckInState.Kiosk.Device.Name ); } var activityType = workflowType.ActivityTypes.Where( a => a.Name == activityName ).FirstOrDefault(); if ( activityType != null ) { WorkflowActivity.Activate( activityType, CurrentWorkflow ); if ( CurrentWorkflow.Process( CurrentCheckInState, out errorMessages ) ) { return true; } } else { errorMessages.Add( string.Format( "Workflow type does not have a '{0}' activity type", activityName ) ); } } else { errorMessages.Add( string.Format( "Invalid Workflow type Id", activityName ) ); } } return false; }
/// <summary> /// Processes the specified workflow. /// </summary> /// <param name="workflow">The workflow.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> public bool Process(Workflow workflow, out List <string> errorMessages) { return(Process(workflow, null, out errorMessages)); }
/// <summary> /// Gets the workflow attributes. /// </summary> /// <param name="workflowTypeId">The workflow type identifier.</param> /// <returns></returns> private List<EntityField> GetWorkflowAttributes( int? workflowTypeId ) { List<EntityField> entityAttributeFields = new List<EntityField>(); if ( workflowTypeId.HasValue ) { var fakeWorkflow = new Rock.Model.Workflow { WorkflowTypeId = workflowTypeId.Value }; Rock.Attribute.Helper.LoadAttributes( fakeWorkflow ); foreach ( var attribute in fakeWorkflow.Attributes.Select( a => a.Value ) ) { EntityHelper.AddEntityFieldForAttribute( entityAttributeFields, attribute ); } } int index = 0; var sortedFields = new List<EntityField>(); foreach ( var entityProperty in entityAttributeFields.OrderBy( p => p.TitleWithoutQualifier ).ThenBy( p => p.Name ) ) { entityProperty.Index = index; index++; sortedFields.Add( entityProperty ); } return sortedFields; }