/// <summary> /// Exports the individuals. /// </summary> /// <param name="modifiedSince">The modified since.</param> /// <param name="peoplePerPage">The people per page.</param> public static void ExportIndividuals(DateTime modifiedSince, int peoplePerPage = 100) { var personAttributes = WritePersonAttributes(); var PCOPeople = GetPeople(false, modifiedSince, API_PEOPLE + "?include=emails,addresses,phone_numbers,field_data,households,inactive_reason,martial_status,name_prefix,name_suffix,primary_campus,school,social_profiles&per_page=" + peoplePerPage); var PCOServicePeople = GetPeople(false, modifiedSince, "https://api.planningcenteronline.com/services/v2/people?per_page=" + peoplePerPage); var PCONotes = GetNotes(false, modifiedSince, null); foreach (PCOPerson p in PCOPeople) { /* For debugging issues with a given person * if ( p.id == 29004938 ) * { * //Debug this profile * Console.WriteLine(); * } */ PCOPerson headOfHouse; if (p.household is null) { headOfHouse = p; } else { headOfHouse = PCOPeople.Where(x => x.id == p.household.primary_contact_id).FirstOrDefault(); } if (headOfHouse == null) { headOfHouse = p; } var importPerson = PCOImportPerson.Translate(p, personAttributes, headOfHouse); if (importPerson != null) { if (PCOServicePeople != null) { PCOPerson backgroundCheckPerson = PCOServicePeople.Where(x => x.id == p.id).FirstOrDefault(); if (backgroundCheckPerson != null && backgroundCheckPerson.passed_background_check.HasValue && backgroundCheckPerson.passed_background_check.Value ) { importPerson = PCOImportPerson.AddBackgroundCheckResult(importPerson, backgroundCheckPerson); } } ImportPackage.WriteToPackage(importPerson); } // save person image if (p.avatar.IsNotNullOrWhitespace()) { WebClient client = new WebClient(); var path = Path.Combine(ImportPackage.ImageDirectory, "Person_" + p.id + ".png"); try { client.DownloadFile(new Uri(p.avatar), path); ApiCounter++; } catch (Exception ex) { Console.WriteLine(ex.Message); } } } // save notes. if (PCONotes != null) { foreach (PCONote note in PCONotes) { PersonNote importNote = PCOImportPersonNote.Translate(note); if (importNote != null) { ImportPackage.WriteToPackage(importNote); } } } }
/// <summary> /// Exports the individuals. /// </summary> /// <param name="modifiedSince">The modified since.</param> /// <param name="peoplePerPage">The people per page.</param> public static void ExportIndividuals(DateTime modifiedSince, int peoplePerPage = 100) { var apiOptions = new Dictionary <string, string> { { "include", "emails,addresses,phone_numbers,field_data,households,inactive_reason,martial_status,name_prefix,name_suffix,primary_campus,school,social_profiles" }, { "per_page", peoplePerPage.ToString() } }; var PCOPeople = GetPeople(ApiEndpoint.API_PEOPLE, apiOptions, modifiedSince); var PCOServicePeople = GetServicePeople(modifiedSince); var PCONotes = GetNotes(modifiedSince); var headOfHouseholdMap = GetHeadOfHouseholdMap(PCOPeople); var personAttributes = WritePersonAttributes(); foreach (var person in PCOPeople) { PersonDTO headOfHouse = person; // Default headOfHouse to person, in case they are not assigned to a household in PCO. if (person.Household != null && headOfHouseholdMap.ContainsKey(person.Household.Id)) { headOfHouse = headOfHouseholdMap[person.Household.Id]; } // The backgroundCheckPerson is pulled from a different API endpoint. PersonDTO backgroundCheckPerson = null; if (PCOServicePeople != null) { backgroundCheckPerson = PCOServicePeople.Where(x => x.Id == person.Id).FirstOrDefault(); } var importPerson = PCOImportPerson.Translate(person, personAttributes, headOfHouse, backgroundCheckPerson); if (importPerson != null) { ImportPackage.WriteToPackage(importPerson); } // save person image if (person.Avatar.IsNotNullOrWhitespace()) { WebClient client = new WebClient(); var path = Path.Combine(ImportPackage.ImageDirectory, "Person_" + person.Id + ".png"); try { client.DownloadFile(new Uri(person.Avatar), path); ApiCounter++; } catch (Exception ex) { Console.WriteLine(ex.Message); } } } // save notes. if (PCONotes != null) { foreach (NoteDTO note in PCONotes) { PersonNote importNote = PCOImportPersonNote.Translate(note); if (importNote != null) { ImportPackage.WriteToPackage(importNote); } } } }