/// <summary> /// Clones this ConnectionActivityType object to a new ConnectionActivityType object /// </summary> /// <param name="source">The source.</param> /// <param name="deepCopy">if set to <c>true</c> a deep copy is made. If false, only the basic entity properties are copied.</param> /// <returns></returns> public static ConnectionActivityType Clone(this ConnectionActivityType source, bool deepCopy) { if (deepCopy) { return(source.Clone() as ConnectionActivityType); } else { var target = new ConnectionActivityType(); target.CopyPropertiesFrom(source); return(target); } }
/// <summary> /// Copies the properties from another ConnectionActivityType object to this ConnectionActivityType object /// </summary> /// <param name="target">The target.</param> /// <param name="source">The source.</param> public static void CopyPropertiesFrom(this ConnectionActivityType target, ConnectionActivityType source) { target.Id = source.Id; target.ConnectionTypeId = source.ConnectionTypeId; target.ForeignGuid = source.ForeignGuid; target.ForeignKey = source.ForeignKey; target.IsActive = source.IsActive; target.Name = source.Name; target.CreatedDateTime = source.CreatedDateTime; target.ModifiedDateTime = source.ModifiedDateTime; target.CreatedByPersonAliasId = source.CreatedByPersonAliasId; target.ModifiedByPersonAliasId = source.ModifiedByPersonAliasId; target.Guid = source.Guid; target.ForeignId = source.ForeignId; }
/// <summary> /// Copies the specified connection type. /// </summary> /// <param name="connectionTypeId">The connection type identifier.</param> /// <returns> /// Return the new ConnectionType ID /// </returns> public int Copy(int connectionTypeId) { var connectionType = this.Get(connectionTypeId); RockContext rockContext = ( RockContext )Context; int newConnectionTypeId = 0; AttributeService attributeService = new AttributeService(rockContext); var authService = new AuthService(rockContext); // Get current Opportunity attributes var opportunityAttributes = attributeService .GetByEntityTypeId(new ConnectionOpportunity().TypeId, true).AsQueryable() .Where(a => a.EntityTypeQualifierColumn.Equals("ConnectionTypeId", StringComparison.OrdinalIgnoreCase) && a.EntityTypeQualifierValue.Equals(connectionType.Id.ToString())) .OrderBy(a => a.Order) .ThenBy(a => a.Name) .ToList(); ConnectionType newConnectionType = new ConnectionType(); rockContext.WrapTransaction(() => { newConnectionType.CopyPropertiesFrom(connectionType); InitModel(ref newConnectionType); newConnectionType.Name = connectionType.Name + " - Copy"; this.Add(newConnectionType); rockContext.SaveChanges(); newConnectionTypeId = newConnectionType.Id; foreach (var connectionActivityTypeState in connectionType.ConnectionActivityTypes) { ConnectionActivityType newConnectionActivityType = new ConnectionActivityType(); newConnectionActivityType.CopyPropertiesFrom(connectionActivityTypeState); InitModel(ref newConnectionActivityType); newConnectionType.ConnectionActivityTypes.Add(newConnectionActivityType); } foreach (var connectionStatusState in connectionType.ConnectionStatuses) { ConnectionStatus newConnectionStatus = new ConnectionStatus(); newConnectionStatus.CopyPropertiesFrom(connectionStatusState); InitModel(ref newConnectionStatus); newConnectionType.ConnectionStatuses.Add(newConnectionStatus); newConnectionStatus.ConnectionTypeId = newConnectionType.Id; } foreach (ConnectionWorkflow connectionWorkflowState in connectionType.ConnectionWorkflows) { ConnectionWorkflow newConnectionWorkflow = new ConnectionWorkflow(); newConnectionWorkflow.CopyPropertiesFrom(connectionWorkflowState); InitModel(ref newConnectionWorkflow); newConnectionType.ConnectionWorkflows.Add(newConnectionWorkflow); newConnectionWorkflow.ConnectionTypeId = newConnectionType.Id; } rockContext.SaveChanges(); // Clone the Opportunity attributes List <Attribute> newAttributesState = new List <Attribute>(); foreach (var attribute in opportunityAttributes) { var newAttribute = attribute.Clone(false); InitModel(ref newAttribute); newAttribute.IsSystem = false; newAttributesState.Add(newAttribute); 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); } } // Save Attributes string qualifierValue = newConnectionType.Id.ToString(); Rock.Attribute.Helper.SaveAttributeEdits(newAttributesState, new ConnectionOpportunity().TypeId, "ConnectionTypeId", qualifierValue, rockContext); // Copy Security Rock.Security.Authorization.CopyAuthorization(connectionType, newConnectionType, rockContext); }); CopyConnectionOpportunities(connectionType, newConnectionType); ConnectionWorkflowService.RemoveCachedTriggers(); return(newConnectionTypeId); }