/// <summary>
 /// Clones this ConnectionOpportunityGroup object to a new ConnectionOpportunityGroup 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 ConnectionOpportunityGroup Clone(this ConnectionOpportunityGroup source, bool deepCopy)
 {
     if (deepCopy)
     {
         return(source.Clone() as ConnectionOpportunityGroup);
     }
     else
     {
         var target = new ConnectionOpportunityGroup();
         target.CopyPropertiesFrom(source);
         return(target);
     }
 }
Exemplo n.º 2
0
        /// <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);
            }
        }