/// <summary> /// Clones this ConnectionOpportunityConnectorGroup object to a new ConnectionOpportunityConnectorGroup 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 ConnectionOpportunityConnectorGroup Clone(this ConnectionOpportunityConnectorGroup source, bool deepCopy) { if (deepCopy) { return(source.Clone() as ConnectionOpportunityConnectorGroup); } else { var target = new ConnectionOpportunityConnectorGroup(); target.CopyPropertiesFrom(source); return(target); } }
/// <summary> /// Copies the properties from another ConnectionOpportunityConnectorGroup object to this ConnectionOpportunityConnectorGroup object /// </summary> /// <param name="target">The target.</param> /// <param name="source">The source.</param> public static void CopyPropertiesFrom(this ConnectionOpportunityConnectorGroup target, ConnectionOpportunityConnectorGroup source) { target.Id = source.Id; target.CampusId = source.CampusId; target.ConnectionOpportunityId = source.ConnectionOpportunityId; target.ConnectorGroupId = source.ConnectorGroupId; target.ForeignGuid = source.ForeignGuid; target.ForeignKey = source.ForeignKey; 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 connection opportunities. /// </summary> /// <param name="connectionType">Source connectionType.</param> /// <param name="newConnectionType">Destination connectionType.</param> private void CopyConnectionOpportunities(ConnectionType connectionType, ConnectionType newConnectionType) { RockContext rockContext = ( RockContext )Context; foreach (ConnectionOpportunity connectionOpportunity in connectionType.ConnectionOpportunities) { ConnectionOpportunity newConnectionOpportunity = new ConnectionOpportunity(); newConnectionOpportunity.CopyPropertiesFrom(connectionOpportunity); InitModel(ref newConnectionOpportunity); newConnectionOpportunity.ConnectionTypeId = newConnectionType.Id; newConnectionType.ConnectionOpportunities.Add(newConnectionOpportunity); rockContext.SaveChanges(); foreach (var connectionWorkflow in connectionOpportunity.ConnectionWorkflows) { ConnectionWorkflow newConnectionWorkflow = new ConnectionWorkflow(); newConnectionWorkflow.CopyPropertiesFrom(connectionWorkflow); InitModel(ref newConnectionWorkflow); newConnectionWorkflow.ConnectionOpportunityId = newConnectionOpportunity.Id; newConnectionOpportunity.ConnectionWorkflows.Add(newConnectionWorkflow); } foreach (var connectionWorkflow in connectionOpportunity.ConnectionType.ConnectionWorkflows) { ConnectionWorkflow newConnectionWorkflow = new ConnectionWorkflow(); newConnectionWorkflow.CopyPropertiesFrom(connectionWorkflow); InitModel(ref newConnectionWorkflow); newConnectionWorkflow.ConnectionOpportunityId = newConnectionOpportunity.Id; newConnectionOpportunity.ConnectionType.ConnectionWorkflows.Add(newConnectionWorkflow); } foreach (var opportunityGroup in connectionOpportunity.ConnectionOpportunityGroups) { ConnectionOpportunityGroup newOpportunityGroup = new ConnectionOpportunityGroup(); newOpportunityGroup.CopyPropertiesFrom(opportunityGroup); InitModel(ref newOpportunityGroup); newOpportunityGroup.ConnectionOpportunityId = newConnectionOpportunity.Id; newConnectionOpportunity.ConnectionOpportunityGroups.Add(newOpportunityGroup); } foreach (var groupConfig in connectionOpportunity.ConnectionOpportunityGroupConfigs) { ConnectionOpportunityGroupConfig newGroupConfig = new ConnectionOpportunityGroupConfig(); newGroupConfig.CopyPropertiesFrom(groupConfig); InitModel(ref newGroupConfig); newGroupConfig.ConnectionOpportunityId = newConnectionOpportunity.Id; newConnectionOpportunity.ConnectionOpportunityGroupConfigs.Add(newGroupConfig); } foreach (var connectorGroup in connectionOpportunity.ConnectionOpportunityConnectorGroups) { ConnectionOpportunityConnectorGroup newConnectorGroup = new ConnectionOpportunityConnectorGroup(); newConnectorGroup.CopyPropertiesFrom(connectorGroup); InitModel(ref newConnectorGroup); newConnectorGroup.ConnectionOpportunityId = newConnectionOpportunity.Id; newConnectionOpportunity.ConnectionOpportunityConnectorGroups.Add(newConnectorGroup); } newConnectionOpportunity.PhotoId = connectionOpportunity.PhotoId; foreach (var campus in connectionOpportunity.ConnectionOpportunityCampuses) { ConnectionOpportunityCampus newCampus = new ConnectionOpportunityCampus(); newCampus.CopyPropertiesFrom(campus); InitModel(ref newCampus); newCampus.ConnectionOpportunityId = newConnectionOpportunity.Id; newConnectionOpportunity.ConnectionOpportunityCampuses.Add(newCampus); } rockContext.SaveChanges(); // Copy attributes connectionOpportunity.LoadAttributes(rockContext); newConnectionOpportunity.LoadAttributes(); if (connectionOpportunity.Attributes != null && connectionOpportunity.Attributes.Any()) { foreach (var attributeKey in connectionOpportunity.Attributes.Select(a => a.Key)) { string value = connectionOpportunity.GetAttributeValue(attributeKey); newConnectionOpportunity.SetAttributeValue(attributeKey, value); } } newConnectionOpportunity.SaveAttributeValues(rockContext); } }