Skip to content
This repository has been archived by the owner on Mar 22, 2019. It is now read-only.

Commit

Permalink
Merge pull request #194 from KingdomFirst/develop
Browse files Browse the repository at this point in the history
Update for Rock 1.7.3
  • Loading branch information
dcs619 authored May 29, 2018
2 parents 3808d11 + a0f3755 commit 909a3c8
Show file tree
Hide file tree
Showing 10 changed files with 614 additions and 128 deletions.
119 changes: 91 additions & 28 deletions Excavator.FellowshipOne/Maps/Notes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public void MapContactFormData( IQueryable<Row> tableData, long totalRows = 0 )
var importedCommunicationCount = new CommunicationService( lookupContext ).Queryable().Count( c => c.ForeignKey != null );
var importedNoteCount = new NoteService( lookupContext ).Queryable().Count( n => n.ForeignKey != null );

var prayerRequestors = new Dictionary<int, Person>();

var communicationList = new List<Communication>();
var prayerList = new List<PrayerRequest>();
var noteList = new List<Note>();

if ( totalRows == 0 )
Expand All @@ -49,7 +52,9 @@ public void MapContactFormData( IQueryable<Row> tableData, long totalRows = 0 )
var individualId = row["ContactIndividualID"] as int?;
var createdDate = row["ContactActivityDate"] as DateTime?;
var modifiedDate = row["ContactDatetime"] as DateTime?;
var approvalDate = row["ContactFormLastUpdatedDate"] as DateTime?;
var itemType = row["ContactFormName"] as string;
var itemStatus = row["ContactStatus"] as string;
var itemCaption = row["ContactItemName"] as string;
var noteText1 = row["ContactNote"] as string;
var noteText2 = row["ContactItemNote"] as string;
Expand Down Expand Up @@ -87,9 +92,27 @@ public void MapContactFormData( IQueryable<Row> tableData, long totalRows = 0 )

communicationList.Add( communication );
}
else if ( !string.IsNullOrWhiteSpace( itemCaption ) && itemCaption.EndsWith( "Prayer Request", StringComparison.CurrentCultureIgnoreCase ) )
{
// create a prayer request
Person requestor = null;
prayerRequestors.TryGetValue( personKeys.PersonId, out requestor );
if ( requestor == null )
{
requestor = lookupContext.People.FirstOrDefault( p => p.Id.Equals( personKeys.PersonId ) );
prayerRequestors.Add( personKeys.PersonId, requestor );
}

var request = AddPrayerRequest( lookupContext, null, personKeys.PersonAliasId, requestor.FirstName, requestor.LastName, requestor.Email, itemText ?? itemCaption, string.Empty,
!itemStatus.Equals( "Closed", StringComparison.CurrentCultureIgnoreCase ), false, createdDate ?? modifiedDate, approvalDate, itemForeignKey.ToString(), userPersonAliasId );
if ( request != null )
{
prayerList.Add( request );
}
}
else
{
//strip campus from note type
//strip campus from type
var campusId = GetCampusId( itemType );
if ( campusId.HasValue )
{
Expand All @@ -113,10 +136,12 @@ public void MapContactFormData( IQueryable<Row> tableData, long totalRows = 0 )
else if ( completedItems % ReportingNumber < 1 )
{
SaveCommunications( communicationList );
SavePrayerRequests( prayerList );
SaveNotes( noteList );
ReportPartialProgress();

communicationList.Clear();
prayerList.Clear();
noteList.Clear();
}
}
Expand All @@ -125,6 +150,7 @@ public void MapContactFormData( IQueryable<Row> tableData, long totalRows = 0 )
if ( communicationList.Any() || noteList.Any() )
{
SaveCommunications( communicationList );
SavePrayerRequests( prayerList );
SaveNotes( noteList );
}

Expand All @@ -142,6 +168,8 @@ public void MapIndividualContactNotes( IQueryable<Row> tableData, long totalRows

var importedNotes = new NoteService( lookupContext ).Queryable().Where( n => n.ForeignId != null )
.ToDictionary( n => n.ForeignId, n => n.Id );
var importedRequests = new PrayerRequestService( lookupContext ).Queryable().Where( r => r.ForeignId != null )
.ToDictionary( r => r.ForeignId, r => r.Id );

var noteList = new List<Note>();
int? confidentialNoteTypeId = null;
Expand Down Expand Up @@ -174,26 +202,38 @@ public void MapIndividualContactNotes( IQueryable<Row> tableData, long totalRows
}

var noteId = 0;
if ( importedNotes.ContainsKey( itemForeignKey ) )
{
noteId = importedNotes[itemForeignKey];
}
var noteEntityId = personKeys.PersonId;
var noteEntityTypeId = PersonEntityTypeId;
var noteTypeId = PersonalNoteTypeId;

// add a confidential note
if ( !string.IsNullOrWhiteSpace( confidentialText ) )
{
var confidential = AddEntityNote( lookupContext, PersonEntityTypeId, personKeys.PersonId, string.Empty, confidentialText, false, false,
var confidential = AddEntityNote( lookupContext, noteEntityTypeId, noteEntityId, string.Empty, confidentialText, false, false,
"Confidential Note", confidentialNoteTypeId, false, createdDate, itemForeignKey.ToString() );
confidentialNoteTypeId = confidential.NoteTypeId;

noteList.Add( confidential );
}

// add a normal note
// this is new or an update to timeline note
if ( importedNotes.ContainsKey( itemForeignKey ) )
{
noteId = importedNotes[itemForeignKey];
}
// note this as a prayer request comment
else if ( importedRequests.ContainsKey( itemForeignKey ) )
{
noteEntityTypeId = PrayerRequestTypeId;
noteEntityId = importedRequests[itemForeignKey];
noteTypeId = PrayerNoteTypeId;
}

// add the note text
if ( !string.IsNullOrWhiteSpace( noteText ) )
{
var note = AddEntityNote( lookupContext, PersonEntityTypeId, personKeys.PersonId, string.Empty, noteText, false, false,
null, PersonalNoteTypeId, false, createdDate, itemForeignKey.ToString() );
var note = AddEntityNote( lookupContext, noteEntityTypeId, noteEntityId, string.Empty, noteText, false, false,
null, noteTypeId, false, createdDate, itemForeignKey.ToString() );
note.Id = noteId;

noteList.Add( note );
Expand Down Expand Up @@ -309,12 +349,32 @@ public void MapNotes( IQueryable<Row> tableData, long totalRows = 0 )
/// <param name="communicationList">The communication list.</param>
private static void SaveCommunications( List<Communication> communicationList )
{
var rockContext = new RockContext();
rockContext.WrapTransaction( () =>
if ( communicationList.Count > 0 )
{
rockContext.Communications.AddRange( communicationList );
rockContext.SaveChanges( DisableAuditing );
} );
var rockContext = new RockContext();
rockContext.WrapTransaction( () =>
{
rockContext.Communications.AddRange( communicationList );
rockContext.SaveChanges( DisableAuditing );
} );
}
}

/// <summary>
/// Saves the prayer requests.
/// </summary>
/// <param name="prayerList">The prayer list.</param>
private static void SavePrayerRequests( List<PrayerRequest> prayerList )
{
if ( prayerList.Count > 0 )
{
var rockContext = new RockContext();
rockContext.WrapTransaction( () =>
{
rockContext.PrayerRequests.AddRange( prayerList );
rockContext.SaveChanges( DisableAuditing );
} );
}
}

/// <summary>
Expand All @@ -323,25 +383,28 @@ private static void SaveCommunications( List<Communication> communicationList )
/// <param name="noteList">The note list.</param>
private static void SaveNotes( List<Note> noteList )
{
var rockContext = new RockContext();
rockContext.WrapTransaction( () =>
if ( noteList.Count > 0 )
{
rockContext.Configuration.AutoDetectChangesEnabled = false;
rockContext.Notes.AddRange( noteList.Where( n => n.Id == 0 ) );

foreach ( var note in noteList.Where( n => n.Id > 0 ) )
var rockContext = new RockContext();
rockContext.WrapTransaction( () =>
{
var existingNote = rockContext.Notes.FirstOrDefault( n => n.Id == note.Id );
if ( existingNote != null )
rockContext.Configuration.AutoDetectChangesEnabled = false;
rockContext.Notes.AddRange( noteList.Where( n => n.Id == 0 ) );

foreach ( var note in noteList.Where( n => n.Id > 0 ) )
{
existingNote.Text += note.Text;
rockContext.Entry( existingNote ).State = EntityState.Modified;
var existingNote = rockContext.Notes.FirstOrDefault( n => n.Id == note.Id );
if ( existingNote != null )
{
existingNote.Text += note.Text;
rockContext.Entry( existingNote ).State = EntityState.Modified;
}
}
}

rockContext.ChangeTracker.DetectChanges();
rockContext.SaveChanges( DisableAuditing );
} );
rockContext.ChangeTracker.DetectChanges();
rockContext.SaveChanges( DisableAuditing );
} );
}
}
}
}
3 changes: 0 additions & 3 deletions Excavator.FellowshipOne/Maps/People.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,6 @@ public void MapPerson( IQueryable<Row> tableData, long totalRows = 0 )
{
person.ConnectionStatusValueId = VisitorConnectionStatusId;
person.RecordStatusValueId = ActivePersonRecordStatusId;

// F1 can designate visitors by member status or household position
familyRoleId = FamilyRole.Visitor;
}
else if ( memberStatus.Equals( "Deceased", StringComparison.CurrentCultureIgnoreCase ) )
{
Expand Down
Loading

0 comments on commit 909a3c8

Please sign in to comment.