private string GetActivityName(ConnectionActivityType activityType) { var activityName = string.Empty; if (activityType != null) { activityName = activityType.Name; if (activityType.ConnectionType != null) { activityName += $" ( {activityType.ConnectionType.Name} )"; } } return(activityName); }
/// <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 ) { ConnectionType connectionType; using ( var rockContext = new RockContext() ) { if ( StatusesState.Any( s => s.IsDefault ) && ActivityTypesState.Any() ) { ConnectionTypeService connectionTypeService = new ConnectionTypeService( rockContext ); ConnectionActivityTypeService connectionActivityTypeService = new ConnectionActivityTypeService( rockContext ); ConnectionStatusService connectionStatusService = new ConnectionStatusService( rockContext ); ConnectionWorkflowService connectionWorkflowService = new ConnectionWorkflowService( rockContext ); AttributeService attributeService = new AttributeService( rockContext ); AttributeQualifierService qualifierService = new AttributeQualifierService( rockContext ); int connectionTypeId = int.Parse( hfConnectionTypeId.Value ); if ( connectionTypeId == 0 ) { connectionType = new ConnectionType(); connectionTypeService.Add( connectionType ); } else { connectionType = connectionTypeService.Queryable( "ConnectionActivityTypes, ConnectionWorkflows" ).Where( c => c.Id == connectionTypeId ).FirstOrDefault(); var uiWorkflows = WorkflowsState.Select( l => l.Guid ); foreach ( var connectionWorkflow in connectionType.ConnectionWorkflows.Where( l => !uiWorkflows.Contains( l.Guid ) ).ToList() ) { connectionType.ConnectionWorkflows.Remove( connectionWorkflow ); connectionWorkflowService.Delete( connectionWorkflow ); } var uiActivityTypes = ActivityTypesState.Select( r => r.Guid ); foreach ( var connectionActivityType in connectionType.ConnectionActivityTypes.Where( r => !uiActivityTypes.Contains( r.Guid ) ).ToList() ) { connectionType.ConnectionActivityTypes.Remove( connectionActivityType ); connectionActivityTypeService.Delete( connectionActivityType ); } var uiStatuses = StatusesState.Select( r => r.Guid ); foreach ( var connectionStatus in connectionType.ConnectionStatuses.Where( r => !uiStatuses.Contains( r.Guid ) ).ToList() ) { connectionType.ConnectionStatuses.Remove( connectionStatus ); connectionStatusService.Delete( connectionStatus ); } } connectionType.Name = tbName.Text; connectionType.Description = tbDescription.Text; connectionType.IconCssClass = tbIconCssClass.Text; connectionType.DaysUntilRequestIdle = nbDaysUntilRequestIdle.Text.AsInteger(); connectionType.EnableFutureFollowup = cbFutureFollowUp.Checked; connectionType.EnableFullActivityList = cbFullActivityList.Checked; connectionType.RequiresPlacementGroupToConnect = cbRequiresPlacementGroup.Checked; foreach ( var connectionActivityTypeState in ActivityTypesState ) { ConnectionActivityType connectionActivityType = connectionType.ConnectionActivityTypes.Where( a => a.Guid == connectionActivityTypeState.Guid ).FirstOrDefault(); if ( connectionActivityType == null ) { connectionActivityType = new ConnectionActivityType(); connectionType.ConnectionActivityTypes.Add( connectionActivityType ); } connectionActivityType.CopyPropertiesFrom( connectionActivityTypeState ); } foreach ( var connectionStatusState in StatusesState ) { ConnectionStatus connectionStatus = connectionType.ConnectionStatuses.Where( a => a.Guid == connectionStatusState.Guid ).FirstOrDefault(); if ( connectionStatus == null ) { connectionStatus = new ConnectionStatus(); connectionType.ConnectionStatuses.Add( connectionStatus ); } connectionStatus.CopyPropertiesFrom( connectionStatusState ); connectionStatus.ConnectionTypeId = connectionType.Id; } foreach ( ConnectionWorkflow connectionWorkflowState in WorkflowsState ) { ConnectionWorkflow connectionWorkflow = connectionType.ConnectionWorkflows.Where( a => a.Guid == connectionWorkflowState.Guid ).FirstOrDefault(); if ( connectionWorkflow == null ) { connectionWorkflow = new ConnectionWorkflow(); connectionType.ConnectionWorkflows.Add( connectionWorkflow ); } else { connectionWorkflowState.Id = connectionWorkflow.Id; connectionWorkflowState.Guid = connectionWorkflow.Guid; } connectionWorkflow.CopyPropertiesFrom( connectionWorkflowState ); connectionWorkflow.ConnectionTypeId = connectionTypeId; } if ( !connectionType.IsValid ) { // Controls will render the error messages return; } // need WrapTransaction due to Attribute saves rockContext.WrapTransaction( () => { rockContext.SaveChanges(); /* Save Attributes */ string qualifierValue = connectionType.Id.ToString(); SaveAttributes( new ConnectionOpportunity().TypeId, "ConnectionTypeId", qualifierValue, AttributesState, rockContext ); connectionType = connectionTypeService.Get( connectionType.Id ); if ( connectionType != null ) { if ( !connectionType.IsAuthorized( Authorization.VIEW, CurrentPerson ) ) { connectionType.AllowPerson( Authorization.VIEW, CurrentPerson, rockContext ); } if ( !connectionType.IsAuthorized( Authorization.EDIT, CurrentPerson ) ) { connectionType.AllowPerson( Authorization.EDIT, CurrentPerson, rockContext ); } if ( !connectionType.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson ) ) { connectionType.AllowPerson( Authorization.ADMINISTRATE, CurrentPerson, rockContext ); } } } ); ConnectionWorkflowService.FlushCachedTriggers(); var qryParams = new Dictionary<string, string>(); qryParams["ConnectionTypeId"] = connectionType.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); } else { nbRequired.Visible = true; } } }
/// <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 mergeFields = GetMergeFields(action); // Get the connection request ConnectionRequest request = null; Guid connectionRequestGuid = action.GetWorklowAttributeValue(GetAttributeValue(action, "ConnectionRequestAttribute").AsGuid()).AsGuid(); request = new ConnectionRequestService(rockContext).Get(connectionRequestGuid); if (request == null) { errorMessages.Add("Invalid Connection Request Attribute or Value!"); return(false); } // Get the activity type ConnectionActivityType activityType = null; Guid activityTypeGuid = action.GetWorklowAttributeValue(GetAttributeValue(action, "ConnectionActivityTypeAttribute").AsGuid()).AsGuid(); activityType = new ConnectionActivityTypeService(rockContext).Get(activityTypeGuid); if (activityType == null) { errorMessages.Add("Invalid Connection Activity Type Attribute or Value!"); return(false); } // Get the note string noteValue = GetAttributeValue(action, "Note", true); string note = string.Empty; Guid? noteGuid = noteValue.AsGuidOrNull(); if (noteGuid.HasValue) { var attribute = AttributeCache.Read(noteGuid.Value, rockContext); if (attribute != null) { note = action.GetWorklowAttributeValue(noteGuid.Value); } } else { note = noteValue; } // Get the connector int? personAliasId = null; Guid?personAttributeGuid = GetAttributeValue(action, "PersonAttribute").AsGuidOrNull(); if (personAttributeGuid.HasValue) { Guid?personAliasGuid = action.GetWorklowAttributeValue(personAttributeGuid.Value).AsGuidOrNull(); if (personAliasGuid.HasValue) { var personAlias = new PersonAliasService(rockContext).Get(personAliasGuid.Value); if (personAlias != null) { personAliasId = personAlias.Id; } } } // Add the activity var activity = new ConnectionRequestActivity(); activity.ConnectionRequestId = request.Id; activity.ConnectionActivityTypeId = activityType.Id; activity.ConnectionOpportunityId = request.ConnectionOpportunityId; activity.ConnectorPersonAliasId = personAliasId; activity.Note = note.ResolveMergeFields(mergeFields); new ConnectionRequestActivityService(rockContext).Add(activity); rockContext.SaveChanges(); return(true); }
/// <summary> /// Handles the Click event of the btnAddConnectionActivityType 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 btnAddConnectionActivityType_Click( object sender, EventArgs e ) { ConnectionActivityType connectionActivityType = null; Guid guid = hfConnectionTypeAddConnectionActivityTypeGuid.Value.AsGuid(); if ( !guid.IsEmpty() ) { connectionActivityType = ActivityTypesState.FirstOrDefault( l => l.Guid.Equals( guid ) ); } if ( connectionActivityType == null ) { connectionActivityType = new ConnectionActivityType(); } connectionActivityType.Name = tbConnectionActivityTypeName.Text; if ( !connectionActivityType.IsValid ) { return; } if ( ActivityTypesState.Any( a => a.Guid.Equals( connectionActivityType.Guid ) ) ) { ActivityTypesState.RemoveEntity( connectionActivityType.Guid ); } ActivityTypesState.Add( connectionActivityType ); BindConnectionActivityTypesGrid(); HideDialog(); }