Ejemplo n.º 1
0
        public static PersonNote Translate(DataRow row)
        {
            var note = new PersonNote();

            note.PersonId = row.Field <int>("IndividualId");
            note.Text     = row.Field <string>("Comment");
            note.NoteType = row.Field <string>("ComtType");

            var date = row.Field <DateTime?>("ComtDate");

            if (date != null)
            {
                note.DateTime = date.Value;
            }

            // generate a unique note id
            MD5 md5Hasher = MD5.Create();
            var hashed    = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(note.PersonId.ToString() + note.Text + note.NoteType));
            var noteId    = Math.Abs(BitConverter.ToInt32(hashed, 0));  // used abs to ensure positive number

            if (noteId > 0)
            {
                note.Id = noteId;
            }

            return(note);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> EditPersonNote(int noteId, string text)
        {
            PersonNote pn = dao.GetPersonNoteById(noteId);

            pn.Comment = text;
            dao.UpdatatePersonNote(pn);
            return(PartialView("_SinglePersonNote", pn));
        }
Ejemplo n.º 3
0
        public async Task <ArenaPostResult> AddNote(int personId, PersonNote personNote)
        {
            Action = String.Format("person/{0}/note", personId);

            HttpRequestMessage request           = new HttpRequestMessage(HttpMethod.Post, Action);
            String             serializedContent = personNote.Serialize();

            request.Content = new StringContent(serializedContent, Encoding.UTF8, "application/xml");

            return(await ExecutePost(request));
        }
Ejemplo n.º 4
0
        public static PersonNote Translate(PCONote inputNote)
        {
            var note = new PersonNote();

            note.PersonId          = inputNote.person_id.Value;
            note.DateTime          = inputNote.created_at;
            note.Id                = inputNote.id;
            note.NoteType          = inputNote.note_category.name;
            note.CreatedByPersonId = inputNote.created_by_id;
            note.Text              = inputNote.note;

            return(note);
        }
Ejemplo n.º 5
0
        public static PersonNote Translate(NoteDTO inputNote)
        {
            var note = new PersonNote
            {
                PersonId          = inputNote.PersonId.Value,
                DateTime          = inputNote.CreatedAt,
                Id                = inputNote.Id,
                NoteType          = inputNote.NoteCategory.Name,
                CreatedByPersonId = inputNote.CreatedById,
                Text              = inputNote.Note
            };

            return(note);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Translate an F1 note into a PersonNote for Rock
        /// </summary>
        /// <param name="row">A single row from the F1 Notes table</param>
        /// <param name="headOfHouseHolds">The subset of F1 individual_household records that are heads of the house</param>
        /// <param name="users">The F1 Users table</param>
        /// <returns></returns>
        public static PersonNote Translate(DataRow row, Dictionary <int, HeadOfHousehold> headOfHouseHolds, DataRow[] users)
        {
            try
            {
                var individualId = row.Field <int?>("Individual_ID");
                var householdId  = row.Field <int?>("Household_ID");

                // Sometimes notes are made for households. Since rock notes go on people, attach that note to the head of household
                if (!individualId.HasValue && householdId.HasValue && headOfHouseHolds.TryGetValue(householdId.Value, out var headOfHousehold))
                {
                    individualId = headOfHousehold?.IndividualId;
                }

                if (!individualId.HasValue)
                {
                    // The note didn't indicate an individual and no valid head of household was found, so not sure what to attach
                    // this note
                    return(null);
                }

                // Determine who the author is by referencing the user table
                var authorUserId   = row.Field <int>("NoteCreatedByUserID");
                var authorUser     = users.FirstOrDefault(u => u.Field <int>("UserID") == authorUserId);
                var authorPersonId = authorUser?.Field <int>("LinkedIndividualID");

                // This field is used twice, so read it outside the literal declaration
                var noteTypeName = row.Field <string>("Note_Type_Name");

                var note = new PersonNote
                {
                    Id                = row.Field <int>("Note_ID"),
                    PersonId          = individualId.Value,
                    CreatedByPersonId = authorPersonId,
                    //Caption
                    DateTime = row.Field <DateTime?>("NoteCreated"),
                    IsAlert  = IsAlert(noteTypeName),
                    //IsPrivateNote
                    NoteType = noteTypeName,
                    Text     = row.Field <string>("Note_Text")
                };

                return(note);
            }
            catch
            {
                return(null);
            }
        }
        public static PersonNote Translate(DataRow row)
        {
            var personNote = new PersonNote();

            personNote.Id       = row.Field <int>("Id");
            personNote.PersonId = row.Field <int>("PersonId");
            personNote.NoteType = row.Field <string>("NoteType");

            // Currently all private notes in Elexio will be public since private notes in
            //  Rock require a created by person and that field is not stored as a person id.
            personNote.IsPrivateNote = false;

            personNote.Text     = row.Field <string>("Text");
            personNote.DateTime = row.Field <DateTime>("DateTime");

            return(personNote);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Takes a dictionary representing a CSV record/row and returns a new Person
        /// Note object with the properties set to the values indicated in the CSV record.
        /// </summary>
        /// <param name="csvRecord"></param>
        /// <returns></returns>
        public static PersonNote Translate(IDictionary <string, object> csvRecord)
        {
            if (csvRecord == null || !csvRecord.Keys.Any())
            {
                return(null);
            }

            // Map the properties of Person Note class to known CSV headers
            // Maybe this could be configurable to the user in the UI if the need arises
            var propertyToCsvFieldNameMap = new Dictionary <string, string> {
                { "PersonId", "Breeze ID" },
                // Id
                { "NoteType", "Username" },
                // Caption
                // IsAlert
                { "IsPrivateNote", "Is Private" },
                { "Text", "Note" },
                { "DateTime", "Created On" }
                // CreatedByPersonId
            };

            // Create a person note object. Using the map, read values from the CSV record and
            // set the associated properties of the person with those values
            var personNote     = new PersonNote();
            var personNoteType = personNote.GetType();

            foreach (var kvp in propertyToCsvFieldNameMap)
            {
                var propertyName = kvp.Key;
                var csvFieldName = kvp.Value;
                var property     = personNoteType.GetProperty(propertyName);
                var value        = CsvFieldTranslators.GetValue(property.PropertyType, csvFieldName, csvRecord);

                property.SetValue(personNote, value);
            }

            // Notetype is mapped to username since there is no great way to match a username to an author person
            if (string.IsNullOrWhiteSpace(personNote.NoteType))
            {
                personNote.NoteType = "Anonymous";
            }

            // TODO store unused values, like username, as attributes when slingshot supports it

            return(personNote);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Exports the person interactions.
        /// </summary>
        public static void ExportPersonInteractions()
        {
            // interactions as notes
            _client  = new RestClient(ElexioCommunityApi.ApiUrl);
            _request = new RestRequest(ElexioCommunityApi.API_INTERACTIONS, Method.GET);
            _request.AddQueryParameter("session_id", ElexioCommunityApi.SessionId);
            _request.AddQueryParameter("start", "1/1/1990");
            _request.AddQueryParameter("count", "10000");
            var response = _client.Execute(_request);

            ElexioCommunityApi.ApiCounter++;

            dynamic interactionData = JsonConvert.DeserializeObject(response.Content);

            var counter = 1000000; // offset to avoid collisions with regular person notes
            var records = interactionData.data.items;

            if (records != null)
            {
                foreach (var interaction in records)
                {
                    string personId = interaction.person.uid;
                    if (personId.AsIntegerOrNull().HasValue)
                    {
                        counter++;

                        PersonNote note = new PersonNote();
                        note.Id       = counter;
                        note.PersonId = personId.AsInteger();
                        note.DateTime = interaction.dateCompleted;
                        note.NoteType = "Legacy Interaction";
                        note.Caption  = interaction.type.name;
                        note.Text     = interaction.summary;

                        string assigned = interaction.assignee.uid;

                        if (assigned.AsIntegerOrNull().HasValue)
                        {
                            note.CreatedByPersonId = assigned.AsInteger();
                        }

                        ImportPackage.WriteToPackage(note);
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public static String Serialize(this PersonNote personNote)
        {
            XmlDocument personNoteDocument = new XmlDocument();

            //add group member
            XmlElement personNoteElement = (XmlElement)personNoteDocument.AppendChild(personNoteDocument.CreateElement("PersonNote"));

            //Active
            personNoteElement.AppendChild(personNoteDocument.CreateElement("Private")).InnerText = (personNote.IsPrivate) ? "true" : "false";

            personNoteElement.AppendChild(personNoteDocument.CreateElement("SecurityTemplateID")).InnerText = personNote.SecurityTemplateId.ToString();

            personNoteElement.AppendChild(personNoteDocument.CreateElement("Text")).InnerText = personNote.Note;


            return(personNoteDocument.OuterXml);
        }
Ejemplo n.º 11
0
        public async Task <ActionResult> AddNote(int id, string note)
        {
            ApplicationUser user   = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());
            Person          person = dao.GetPersonById(id);
            PersonNote      pn     = new PersonNote()
            {
                Author   = user.FirstName + " " + user.Surname,
                AuthorId = user.Id,
                Person   = person,
                Comment  = note,
                Date     = DateTime.Now,
            };

            person.Notes.Add(pn);
            dao.UpdatatePerson(person);

            return(RedirectToAction("ShowNotes", new { id = person.Id }));
        }
Ejemplo n.º 12
0
        /// <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);
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public async Task <ActionResult> EditPersonNote(int noteId)
        {
            PersonNote pn = dao.GetPersonNoteById(noteId);

            return(PartialView("_EditPersonNote", pn));
        }
Ejemplo n.º 14
0
        public static Person Translate(DataRow row)
        {
            var person = new Person();
            var notes  = new List <string>();

            if (row.Field <int?>("Id") != null)
            {
                person.Id = row.Field <int>("Id");

                // names
                person.FirstName  = row.Field <string>("FirstName");
                person.NickName   = row.Field <string>("NickName");
                person.MiddleName = row.Field <string>("MiddleName");
                person.LastName   = row.Field <string>("LastName");

                var suffix = row.Field <string>("Suffix");
                switch (suffix)
                {
                case "v":
                    person.Suffix = "V";
                    break;

                case "mr":
                    break;

                case "Jr":
                    person.Suffix = "Jr.";
                    break;

                case "Sr":
                    person.Suffix = "Sr.";
                    break;

                default:
                    person.Suffix = suffix;
                    break;
                }

                // family
                person.FamilyId   = row.Field <int?>("FamilyId");
                person.FamilyName = row.Field <string>("FamilyName");

                var familyRole = row.Field <string>("familyRole");
                switch (familyRole)
                {
                case "Household Head":
                    person.FamilyRole = FamilyRole.Adult;
                    break;

                case "Spouse of Head":
                    person.FamilyRole = FamilyRole.Adult;
                    break;

                case "Child 1st":
                    person.FamilyRole = FamilyRole.Child;
                    break;

                case "Child 2nd":
                    person.FamilyRole = FamilyRole.Child;
                    break;

                case "Child 3rd":
                    person.FamilyRole = FamilyRole.Child;
                    break;

                case "Child 4th":
                    person.FamilyRole = FamilyRole.Child;
                    break;

                case "Child 5th":
                    person.FamilyRole = FamilyRole.Child;
                    break;

                case "Child 6th":
                    person.FamilyRole = FamilyRole.Child;
                    break;

                case "Child 7th":
                    person.FamilyRole = FamilyRole.Child;
                    break;

                case "Child 8th":
                    person.FamilyRole = FamilyRole.Child;
                    break;

                default:
                    person.FamilyRole = FamilyRole.Child;
                    break;
                }

                notes.Add("Family Role: " + familyRole);

                // email
                person.Email = row.Field <string>("Email");

                var emailPreference = row.Field <string>("EmailOptOut").AsBoolean();
                if (emailPreference)
                {
                    person.EmailPreference = EmailPreference.DoNotEmail;
                }
                else
                {
                    person.EmailPreference = EmailPreference.EmailAllowed;
                }


                // gender
                var gender = row.Field <bool>("Gender");

                if (gender == true)
                {
                    person.Gender = Gender.Male;
                }
                else if (gender == false)
                {
                    person.Gender = Gender.Female;
                }

                // marital status
                var maritalStatus = row.Field <string>("MaritalStatus");
                switch (maritalStatus)
                {
                case "Married":
                    person.MaritalStatus = MaritalStatus.Married;

                    // since anniversary date is a family field, only apply it to married people.
                    person.AnniversaryDate = row.Field <DateTime?>("AnniversaryDate");
                    break;

                case "Single":
                    person.MaritalStatus = MaritalStatus.Single;
                    break;

                case "Divorce":
                    person.MaritalStatus = MaritalStatus.Divorced;
                    break;

                default:
                    person.MaritalStatus = MaritalStatus.Unknown;
                    if (maritalStatus.IsNotNullOrWhitespace())
                    {
                        notes.Add("Marital Status: " + maritalStatus);
                    }
                    break;
                }

                // connection/record status
                string status = row.Field <string>("ConnectionStatus");
                person.ConnectionStatus = status;

                person.RecordStatus = RecordStatus.Active;

                switch (status)
                {
                case "Deceased":
                    person.RecordStatus   = RecordStatus.Inactive;
                    person.InactiveReason = "Deceased";
                    person.IsDeceased     = true;
                    break;

                case "Moved Away":
                    person.RecordStatus   = RecordStatus.Inactive;
                    person.InactiveReason = status;
                    break;

                case "Drop Out Reason Unknown":
                    person.RecordStatus   = RecordStatus.Inactive;
                    person.InactiveReason = status;
                    break;

                case "Left to Another Church":
                    person.RecordStatus   = RecordStatus.Inactive;
                    person.InactiveReason = status;
                    break;
                }

                // dates
                person.CreatedDateTime  = row.Field <DateTime?>("CreatedDateTime");
                person.ModifiedDateTime = row.Field <DateTime?>("ModifiedDateTime");
                person.Birthdate        = row.Field <DateTime?>("Birthdate");

                // gives individually
                var givesIndividually = row.Field <bool?>("GiveIndividually");
                if (givesIndividually.HasValue)
                {
                    person.GiveIndividually = givesIndividually;
                }

                // if the person is a child, their giving is always separate
                if (person.FamilyRole == FamilyRole.Child)
                {
                    person.GiveIndividually = true;
                }

                // campus
                var campusName = row.Field <string>("Campus");
                var CampusId   = row.Field <int>("CampusId");
                if (campusName.IsNotNullOrWhitespace() && CampusId > 0)
                {
                    var campus = new Campus();
                    campus.CampusName = campusName;
                    campus.CampusId   = CampusId;

                    person.Campus = campus;
                }

                // attributes
                var membershipDate = row.Field <DateTime?>("MembershipDate");
                if (membershipDate.HasValue)
                {
                    person.Attributes.Add(new PersonAttributeValue
                    {
                        AttributeKey   = "MembershipDate",
                        AttributeValue = membershipDate.Value.ToString("o"),
                        PersonId       = person.Id
                    });
                }

                var school = row.Field <string>("School");
                if (school.IsNotNullOrWhitespace())
                {
                    person.Attributes.Add(new PersonAttributeValue
                    {
                        AttributeKey   = "School",
                        AttributeValue = school,
                        PersonId       = person.Id
                    });
                }

                var race = row.Field <string>("Race");
                if (race.IsNotNullOrWhitespace())
                {
                    person.Attributes.Add(new PersonAttributeValue
                    {
                        AttributeKey   = "Race",
                        AttributeValue = race,
                        PersonId       = person.Id
                    });
                }

                var occupation = row.Field <string>("Occupation");
                if (occupation.IsNotNullOrWhitespace())
                {
                    person.Attributes.Add(new PersonAttributeValue
                    {
                        AttributeKey   = "Occupation",
                        AttributeValue = occupation,
                        PersonId       = person.Id
                    });
                }

                var education = row.Field <string>("Education");
                if (education.IsNotNullOrWhitespace())
                {
                    person.Attributes.Add(new PersonAttributeValue
                    {
                        AttributeKey   = "Education",
                        AttributeValue = education,
                        PersonId       = person.Id
                    });
                }

                var baptismDate = row.Field <DateTime?>("BaptismDate");
                if (baptismDate != null)
                {
                    person.Attributes.Add(new PersonAttributeValue
                    {
                        AttributeKey   = "BaptismDate",
                        AttributeValue = baptismDate.Value.ToString("o"),
                        PersonId       = person.Id
                    });
                }

                var baptizedHere = row.Field <string>("BaptizedHere");
                if (baptizedHere.IsNotNullOrWhitespace())
                {
                    person.Attributes.Add(new PersonAttributeValue
                    {
                        AttributeKey   = "BaptizedHere",
                        AttributeValue = baptizedHere,
                        PersonId       = person.Id
                    });
                }

                var ageGroup = row.Field <string>("AgeGroup");
                if (ageGroup.IsNotNullOrWhitespace())
                {
                    person.Attributes.Add(new PersonAttributeValue
                    {
                        AttributeKey   = "AgeGroup",
                        AttributeValue = ageGroup,
                        PersonId       = person.Id
                    });
                }

                var bgDate = row.Field <DateTime?>("BackgroundCheckDate");
                if (bgDate.HasValue)
                {
                    person.Attributes.Add(new PersonAttributeValue
                    {
                        AttributeKey   = "BackgroundCheckDate",
                        AttributeValue = bgDate.Value.ToString("o"),
                        PersonId       = person.Id
                    });
                }

                var bgResult = row.Field <string>("BackgroundCheckResult");
                if (bgResult.IsNotNullOrWhitespace())
                {
                    person.Attributes.Add(new PersonAttributeValue
                    {
                        AttributeKey   = "BackgroundCheckResult",
                        AttributeValue = bgResult,
                        PersonId       = person.Id
                    });
                }

                var allergy = row.Field <string>("Allergy");
                if (allergy.IsNotNullOrWhitespace())
                {
                    person.Attributes.Add(new PersonAttributeValue
                    {
                        AttributeKey   = "Allergy",
                        AttributeValue = allergy,
                        PersonId       = person.Id
                    });
                }

                var medical = row.Field <string>("Medical");
                if (medical.IsNotNullOrWhitespace())
                {
                    person.Attributes.Add(new PersonAttributeValue
                    {
                        AttributeKey   = "Medical",
                        AttributeValue = medical,
                        PersonId       = person.Id
                    });
                }

                // social media attributes
                var facebook = row.Field <string>("Facebook");
                if (facebook.IsNotNullOrWhitespace())
                {
                    person.Attributes.Add(new PersonAttributeValue
                    {
                        AttributeKey   = "Facebook",
                        AttributeValue = facebook,
                        PersonId       = person.Id
                    });
                }

                var instagram = row.Field <string>("Instagram");
                if (instagram.IsNotNullOrWhitespace())
                {
                    person.Attributes.Add(new PersonAttributeValue
                    {
                        AttributeKey   = "Instagram",
                        AttributeValue = instagram,
                        PersonId       = person.Id
                    });
                }

                var twitter = row.Field <string>("Twitter");
                if (twitter.IsNotNullOrWhitespace())
                {
                    person.Attributes.Add(new PersonAttributeValue
                    {
                        AttributeKey   = "Twitter",
                        AttributeValue = twitter,
                        PersonId       = person.Id
                    });
                }

                var linkedin = row.Field <string>("LinkedIn");
                if (linkedin.IsNotNullOrWhitespace())
                {
                    person.Attributes.Add(new PersonAttributeValue
                    {
                        AttributeKey   = "LinkedIn",
                        AttributeValue = linkedin,
                        PersonId       = person.Id
                    });
                }

                // phone numbers
                // home
                var homePhone = row.Field <string>("HomePhone");
                if (homePhone.IsNotNullOrWhitespace())
                {
                    // since the phone number could have invalid information, all non digits will be removed
                    if (homePhone.AsNumeric().IsNotNullOrWhitespace() && homePhone.AsNumeric().Count() <= 20)
                    {
                        person.PhoneNumbers.Add(new PersonPhone
                        {
                            PhoneNumber = homePhone.AsNumeric(),
                            PersonId    = person.Id,
                            PhoneType   = "Home",
                            IsUnlisted  = false
                        });
                    }
                }

                // cell
                var cellPhone = row.Field <string>("MobilePhone");
                if (cellPhone.IsNotNullOrWhitespace())
                {
                    // since the phone number could have invalid information, all non digits will be removed
                    if (cellPhone.AsNumeric().IsNotNullOrWhitespace() && cellPhone.AsNumeric().Count() <= 20)
                    {
                        var isMessagingEnabled = row.Field <string>("IsMessagingEnabled").AsBoolean();

                        person.PhoneNumbers.Add(new PersonPhone
                        {
                            PhoneNumber        = cellPhone.AsNumeric(),
                            PersonId           = person.Id,
                            PhoneType          = "Mobile",
                            IsMessagingEnabled = isMessagingEnabled,
                            IsUnlisted         = false
                        });
                    }
                }

                // work
                var workPhone = row.Field <string>("WorkPhone");
                if (workPhone.IsNotNullOrWhitespace())
                {
                    // since the phone number could have invalid information, all non digits will be removed
                    if (workPhone.AsNumeric().IsNotNullOrWhitespace() && workPhone.AsNumeric().Count() <= 20)
                    {
                        person.PhoneNumbers.Add(new PersonPhone
                        {
                            PhoneNumber = workPhone.AsNumeric(),
                            PersonId    = person.Id,
                            PhoneType   = "Work",
                            IsUnlisted  = false
                        });
                    }
                }

                // household address
                var street  = row.Field <string>("Street");
                var city    = row.Field <string>("City");
                var state   = row.Field <string>("State");
                var zip     = row.Field <string>("ZipCode");
                var country = row.Field <string>("Country");

                if (street.IsNotNullOrWhitespace() &&
                    city.IsNotNullOrWhitespace() &&
                    state.IsNotNullOrWhitespace() &&
                    zip.IsNotNullOrWhitespace())
                {
                    person.Addresses.Add(new PersonAddress
                    {
                        PersonId   = person.Id,
                        Street1    = street,
                        City       = city,
                        State      = state,
                        PostalCode = zip,
                        Country    = country
                    });
                }

                // Add Import Note
                if (notes.Any())
                {
                    var personNote = new PersonNote();
                    personNote.PersonId = person.Id;
                    personNote.NoteType = "Import Notes";
                    personNote.DateTime = DateTime.Now;
                    personNote.Text     = string.Join(",", notes);

                    ImportPackage.WriteToPackage(personNote);
                }

                return(person);
            }

            return(null);
        }
Ejemplo n.º 15
0
        public static Person Translate(dynamic importPerson)
        {
            var person = new Person();

            person.Id        = importPerson.uid;
            person.FirstName = importPerson.fname;
            person.NickName  = importPerson.preferredName;
            person.LastName  = importPerson.lname;
            person.Email     = importPerson.mail;

            // secondary email
            string secondEmail = importPerson.secondaryEmail;

            if (secondEmail.IsNotNullOrWhitespace())
            {
                PersonNote emailNote = new PersonNote();
                emailNote.PersonId = person.Id;
                emailNote.NoteType = "Secondary Email";
                emailNote.Text     = secondEmail;

                // offset the Id by 1 million so that these notes do not overlap.
                emailNote.Id = 1000000 + person.Id;

                ImportPackage.WriteToPackage(emailNote);
            }

            // gender
            if (importPerson.male == "1")
            {
                person.Gender = Gender.Male;
            }
            else
            {
                person.Gender = Gender.Female;
            }

            // marital status is not a built in field
            person.MaritalStatus = MaritalStatus.Unknown;

            // connection status is not a built in field
            person.ConnectionStatus = "Unknown";

            // family
            var _client  = new RestClient(ElexioCommunityApi.ApiUrl);
            var _request = new RestRequest(ElexioCommunityApi.API_INDIVIDUAL + person.Id.ToString(), Method.GET);

            _request.AddQueryParameter("session_id", ElexioCommunityApi.SessionId);
            var response = _client.Execute(_request);

            ElexioCommunityApi.ApiCounter++;

            dynamic data = JsonConvert.DeserializeObject(response.Content);

            JArray familyMembers = data.data.family;

            if (familyMembers != null)
            {
                foreach (var member in familyMembers)
                {
                    // look for person in family members
                    if (person.Id == (int)member["uid"])
                    {
                        // get family role
                        string role = member["relationship"].ToString();
                        if (role == "Father" || role == "Mother" || role == "Husband" || role == "Wife" || role == "Primary")
                        {
                            person.FamilyRole = FamilyRole.Adult;
                        }
                        else
                        {
                            person.FamilyRole = FamilyRole.Child;
                        }

                        // get family id
                        person.FamilyId = (int)member["fid"];

                        // get giving setting
                        person.GiveIndividually = !(bool)member["givesWithFamily"];
                    }
                }
            }

            // it is possible that the person if not in a family so one will needs to be generated
            if (person.FamilyId == null)
            {
                person.FamilyId         = person.Id + 1000000;
                person.FamilyRole       = FamilyRole.Adult;
                person.GiveIndividually = true;
            }

            // phone numbers
            string homePhone = importPerson.phoneHome;

            if (homePhone != null && homePhone.AsNumeric().IsNotNullOrWhitespace())
            {
                var phone = new PersonPhone();
                phone.PhoneType   = "Home";
                phone.PhoneNumber = homePhone.AsNumeric();
                phone.PersonId    = person.Id;

                person.PhoneNumbers.Add(phone);
            }

            string cellPhone = importPerson.phoneCell;

            if (cellPhone != null && cellPhone.AsNumeric().IsNotNullOrWhitespace())
            {
                var phone = new PersonPhone();
                phone.PhoneType          = "Mobile";
                phone.PhoneNumber        = cellPhone.AsNumeric();
                phone.IsMessagingEnabled = true;
                phone.PersonId           = person.Id;

                person.PhoneNumbers.Add(phone);
            }

            string workPhone = importPerson.phoneWork;

            if (workPhone != null && workPhone.AsNumeric().IsNotNullOrWhitespace())
            {
                var phone = new PersonPhone();
                phone.PhoneType   = "Work";
                phone.PhoneNumber = workPhone.AsNumeric();
                phone.PersonId    = person.Id;

                person.PhoneNumbers.Add(phone);
            }

            // address 1
            string street1    = importPerson.address;
            string city       = importPerson.city;
            string state      = importPerson.state;
            string postalcode = importPerson.zipcode;

            if (street1.IsNotNullOrWhitespace() && city.IsNotNullOrWhitespace() &&
                state.IsNotNullOrWhitespace() && postalcode.IsNotNullOrWhitespace())
            {
                var address = new PersonAddress();
                address.PersonId    = person.Id;
                address.Street1     = street1;
                address.City        = city;
                address.State       = state;
                address.PostalCode  = postalcode;
                address.Country     = importPerson.country;
                address.AddressType = AddressType.Home;

                person.Addresses.Add(address);
            }

            // address 2
            street1    = importPerson.address2;
            city       = importPerson.city2;
            state      = importPerson.state2;
            postalcode = importPerson.zipcode2;

            if (street1.IsNotNullOrWhitespace() && city.IsNotNullOrWhitespace() &&
                state.IsNotNullOrWhitespace() && postalcode.IsNotNullOrWhitespace())
            {
                var address = new PersonAddress();
                address.PersonId    = person.Id;
                address.Street1     = street1;
                address.City        = city;
                address.State       = state;
                address.PostalCode  = postalcode;
                address.Country     = importPerson.country;
                address.AddressType = AddressType.Other;

                person.Addresses.Add(address);
            }

            // envelope number
            string envelopeNumber = importPerson.envNum;

            if (envelopeNumber.AsIntegerOrNull().HasValue&& envelopeNumber.AsIntegerOrNull().Value > 0)
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = "core_GivingEnvelopeNumber",
                    AttributeValue = envelopeNumber
                });
            }

            //// dates ////
            // created/modified date
            string updatedDate = importPerson.updated;

            if (updatedDate.IsNotNullOrWhitespace())
            {
                person.CreatedDateTime  = UnixTimeStampToDateTime(updatedDate.AsDouble());
                person.ModifiedDateTime = UnixTimeStampToDateTime(updatedDate.AsDouble());
            }

            // date of birth
            string birthdate = importPerson.dateBirth;

            if (birthdate.AsDateTime().HasValue)
            {
                person.Birthdate = birthdate.AsDateTime().Value;
            }

            // baptism date
            string baptismDate = importPerson.dateBaptism;

            if (baptismDate.AsDateTime().HasValue)
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = "BaptismDate",
                    AttributeValue = baptismDate.AsDateTime().Value.ToString("o")
                });
            }

            // check for deceased
            string dateDied = importPerson.dateDied;

            if (dateDied.AsDateTime().HasValue)
            {
                person.IsDeceased = true;

                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = "DeathDate",
                    AttributeValue = dateDied.AsDateTime().Value.ToString("o")
                });
            }

            // last attended
            string lastAttended = importPerson.timeLastAttended;

            if (lastAttended.AsDouble() > 0)
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = "LastAttended",
                    AttributeValue = UnixTimeStampToDateTime(lastAttended.AsDouble()).ToString("o")
                });
            }

            #region Attributes

            //// attributes
            MetaData metaData = ElexioCommunityApi.MetaData;

            //// dates 1 - 10
            // date 1
            string date1 = importPerson.date1;
            if (metaData.data.dateFieldLabels.date1 != null && date1.AsDateTime().HasValue)
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.dateFieldLabels.date1.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = date1.AsDateTime().Value.ToString("o")
                });
            }

            // date 2
            string date2 = importPerson.date2;
            if (metaData.data.dateFieldLabels.date2 != null && date2.AsDateTime().HasValue)
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.dateFieldLabels.date2.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = date2.AsDateTime().Value.ToString("o")
                });
            }

            // date 3
            string date3 = importPerson.date3;
            if (metaData.data.dateFieldLabels.date3 != null && date3.AsDateTime().HasValue)
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.dateFieldLabels.date3.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = date3.AsDateTime().Value.ToString("o")
                });
            }

            // date 4
            string date4 = importPerson.date4;
            if (metaData.data.dateFieldLabels.date4 != null && date4.AsDateTime().HasValue)
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.dateFieldLabels.date4.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = date4.AsDateTime().Value.ToString("o")
                });
            }

            // date 5
            string date5 = importPerson.date5;
            if (metaData.data.dateFieldLabels.date5 != null && date5.AsDateTime().HasValue)
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.dateFieldLabels.date5.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = date5.AsDateTime().Value.ToString("o")
                });
            }

            // date 6
            string date6 = importPerson.date6;
            if (metaData.data.dateFieldLabels.date6 != null && date6.AsDateTime().HasValue)
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.dateFieldLabels.date6.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = date6.AsDateTime().Value.ToString("o")
                });
            }

            // date 7
            string date7 = importPerson.date7;
            if (metaData.data.dateFieldLabels.date7 != null && date7.AsDateTime().HasValue)
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.dateFieldLabels.date7.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = date7.AsDateTime().Value.ToString("o")
                });
            }

            // date 8
            string date8 = importPerson.date8;
            if (metaData.data.dateFieldLabels.date8 != null && date8.AsDateTime().HasValue)
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.dateFieldLabels.date8.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = date8.AsDateTime().Value.ToString("o")
                });
            }

            // date 9
            string date9 = importPerson.date9;
            if (metaData.data.dateFieldLabels.date9 != null && date9.AsDateTime().HasValue)
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.dateFieldLabels.date9.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = date9.AsDateTime().Value.ToString("o")
                });
            }

            // date 1
            string date10 = importPerson.date10;
            if (metaData.data.dateFieldLabels.date10 != null && date10.AsDateTime().HasValue)
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.dateFieldLabels.date10.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = date10.AsDateTime().Value.ToString("o")
                });
            }

            //// text 1 - 15
            // text 1
            string text1 = importPerson.text1;
            if (metaData.data.textFieldLabels.text1 != null && text1.IsNotNullOrWhitespace())
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.textFieldLabels.text1.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = importPerson.text1
                });
            }

            // text 2
            string text2 = importPerson.text2;
            if (metaData.data.textFieldLabels.text2 != null && text2.IsNotNullOrWhitespace())
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.textFieldLabels.text2.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = importPerson.text2
                });
            }

            // text 3
            string text3 = importPerson.text3;
            if (metaData.data.textFieldLabels.text3 != null && text3.IsNotNullOrWhitespace())
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.textFieldLabels.text3.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = importPerson.text3
                });
            }

            // text 4
            string text4 = importPerson.text4;
            if (metaData.data.textFieldLabels.text4 != null && text4.IsNotNullOrWhitespace())
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.textFieldLabels.text4.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = importPerson.text4
                });
            }

            // text 5
            string text5 = importPerson.text5;
            if (metaData.data.textFieldLabels.text5 != null && text5.IsNotNullOrWhitespace())
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.textFieldLabels.text5.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = importPerson.text5
                });
            }

            // text 6
            string text6 = importPerson.text6;
            if (metaData.data.textFieldLabels.text6 != null && text6.IsNotNullOrWhitespace())
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.textFieldLabels.text6.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = importPerson.text6
                });
            }

            // text 7
            string text7 = importPerson.text7;
            if (metaData.data.textFieldLabels.text7 != null && text7.IsNotNullOrWhitespace())
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.textFieldLabels.text7.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = importPerson.text7
                });
            }

            // text 8
            string text8 = importPerson.text8;
            if (metaData.data.textFieldLabels.text8 != null && text8.IsNotNullOrWhitespace())
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.textFieldLabels.text8.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = importPerson.text8
                });
            }

            // text 9
            string text9 = importPerson.text9;
            if (metaData.data.textFieldLabels.text9 != null && text9.IsNotNullOrWhitespace())
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.textFieldLabels.text9.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = importPerson.text9
                });
            }

            // text 10
            string text10 = importPerson.text10;
            if (metaData.data.textFieldLabels.text10 != null && text10.IsNotNullOrWhitespace())
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.textFieldLabels.text10.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = importPerson.text10
                });
            }

            // text 11
            string text11 = importPerson.text11;
            if (metaData.data.textFieldLabels.text11 != null && text11.IsNotNullOrWhitespace())
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.textFieldLabels.text11.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = importPerson.text11
                });
            }

            // text 12
            string text12 = importPerson.text12;
            if (metaData.data.textFieldLabels.text12 != null && text12.IsNotNullOrWhitespace())
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.textFieldLabels.text12.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = importPerson.text12
                });
            }

            // text 13
            string text13 = importPerson.text13;
            if (metaData.data.textFieldLabels.text13 != null && text13.IsNotNullOrWhitespace())
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.textFieldLabels.text13.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = importPerson.text13
                });
            }

            // text 14
            string text14 = importPerson.text14;
            if (metaData.data.textFieldLabels.text14 != null && text14.IsNotNullOrWhitespace())
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.textFieldLabels.text14.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = importPerson.text14
                });
            }

            // text 15
            string text15 = importPerson.text15;
            if (metaData.data.textFieldLabels.text15 != null && text15.IsNotNullOrWhitespace())
            {
                person.Attributes.Add(new PersonAttributeValue()
                {
                    PersonId       = person.Id,
                    AttributeKey   = metaData.data.textFieldLabels.text15.RemoveSpaces().RemoveSpecialCharacters(),
                    AttributeValue = importPerson.text15
                });
            }

            #endregion

            return(person);
        }
Ejemplo n.º 16
0
        /// <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);
                    }
                }
            }
        }