/// <summary> /// Adds the connections requests to the system from the given XML element. /// </summary> /// <example> /// <connections> /// <connection type="Involvement" opportunity="Children's" comment="I would love to help teach kids about Jesus." date="2015-10-11T00:00:00" personGuid="1dfff821-e97c-4324-9883-cf59b5c5bdd6" /> /// </connections> /// </example> /// <param name="elemConnections">The elem connections.</param> /// <param name="rockContext">The rock context.</param> private void AddConnections( XElement elemConnections, RockContext rockContext ) { if ( elemConnections == null ) { return; } ConnectionRequestService crService = new ConnectionRequestService( rockContext ); ConnectionOpportunityService coService = new ConnectionOpportunityService( rockContext ); ConnectionTypeService typeService = new ConnectionTypeService( rockContext ); ConnectionStatusService connectionStatusService = new ConnectionStatusService( rockContext ); ConnectionStatus noContact = connectionStatusService.Get( "901e1a6a-0e91-4f42-880f-47c061c24e0c".AsGuid() ); // Find the type and it's corresponding opportunity and then add a connection request for the given person. foreach ( var element in elemConnections.Elements( "connection" ) ) { string connectionTypeName = element.Attribute( "type" ).Value.Trim(); string opportunityName = element.Attribute( "opportunity" ).Value.Trim(); string comment = element.Attribute( "comment" ).Value.Trim(); DateTime date = DateTime.Parse( element.Attribute( "date" ).Value.Trim(), new CultureInfo( "en-US" ) ); Guid personGuid = element.Attribute( "personGuid" ).Value.Trim().AsGuid(); var connectionOpportunity = coService.Queryable( "ConnectionType" ).AsNoTracking().Where( co => co.ConnectionType.Name == connectionTypeName && co.Name == opportunityName ).FirstOrDefault(); // make sure we found a matching connection opportunity if ( connectionOpportunity != null ) { ConnectionRequest connectionRequest = new ConnectionRequest() { ConnectionOpportunityId = connectionOpportunity.Id, PersonAliasId = _peopleAliasDictionary[personGuid], Comments = comment, ConnectionStatus = noContact, ConnectionState = global::ConnectionState.Active, CreatedDateTime = date }; crService.Add( connectionRequest ); } } }