示例#1
0
        public override void ExportRecord( string identifier)
        {
            int personId = 0;

            if ( !int.TryParse( identifier, out personId ) )
            {
                OnExportAttemptCompleted( identifier, false );
                return;
            }

            Person arenaPerson = GetArenaPerson( personId );

            if ( arenaPerson == null )
            {
                OnExportAttemptCompleted( identifier, false );
                return;
            }

            RockMaps.PersonMap rockPersonMap = new BAL.RockMaps.PersonMap( Service );
            Dictionary<string, object> rockPerson = rockPersonMap.GetByForeignId( identifier );

            int? rockPersonId = null;

            if ( rockPerson == null )
            {
                int? rockFamilyId = GetRockFamily( arenaPerson.FamilyMember.FirstOrDefault().Family );

                int recordTypeValueId = arenaPerson.business ? rockPersonMap.GetRecordTypeBusiness() : rockPersonMap.GetRecordTypePerson();

                int recordStatusValueId;

                switch ( arenaPerson.record_status )
                {
                    case 0:
                        recordStatusValueId = rockPersonMap.GetRecordStatusIdActive();
                        break;
                    case 1:
                        recordStatusValueId = rockPersonMap.GetRecordStatusIdInactive();
                        break;
                    case 2:
                        recordStatusValueId = rockPersonMap.GetRecordStatusIdPending();
                        break;
                    default:
                        recordStatusValueId = rockPersonMap.GetRecordStatusIdPending();
                        break;
                }

                int? recordStatusReasonId = null;

                if ( arenaPerson.inactive_reason_luid != null )
                {
                    recordStatusReasonId = GetDefinedValueIdByForeignId( arenaPerson.inactive_reason_luid );

                }

                bool isDeceased = recordStatusReasonId == rockPersonMap.GetRecordStatusReasonIdDeceased();

                int? connectionStatusValueID = GetDefinedValueIdByForeignId( arenaPerson.member_status );

                int? titleValueId = null;

                if ( arenaPerson.title_luid != null )
                {
                    titleValueId = GetDefinedValueIdByForeignId( arenaPerson.title_luid );
                }

                int? suffixValueId = null;

                if ( arenaPerson.suffix_luid != null )
                {
                    suffixValueId = GetDefinedValueIdByForeignId( arenaPerson.suffix_luid );
                }

                int? birthYear = null;
                int? birthMonth = null;
                int? birthDay = null;

                if ( arenaPerson.birth_date != null && arenaPerson.birth_date > new DateTime( 1900, 1, 1 ) )
                {
                    birthYear = arenaPerson.birth_date.Year;
                    birthMonth = arenaPerson.birth_date.Month;
                    birthDay = arenaPerson.birth_date.Day;
                }

                int gender;

                switch ( arenaPerson.gender )
                {
                    case 0:
                        gender = 1;
                        break;
                    case 1:
                        gender = 2;
                        break;
                    case 2:
                        gender = 0;
                        break;
                    default:
                        gender = 0;
                        break;
                }

                int? maritalStatusValueId = null;

                if ( arenaPerson.marital_status != null )
                {
                    maritalStatusValueId = GetDefinedValueIdByForeignId( arenaPerson.marital_status );
                }

                DateTime? anniversaryDate = null;

                if ( arenaPerson.anniversary_date != null && arenaPerson.anniversary_date > new DateTime( 1900, 1, 1 ) )
                {
                    anniversaryDate = arenaPerson.anniversary_date;
                }

                DateTime? graduationDate = null;

                if ( arenaPerson.graduation_date != null && arenaPerson.graduation_date > new DateTime( 1900, 1, 1 ) )
                {
                    graduationDate = arenaPerson.graduation_date;
                }

                int? givingGroupId = null;

                if ( !arenaPerson.contribute_individually )
                {
                    givingGroupId = rockFamilyId;
                }

                string primaryEmailAddress = null;
                string emailNote = null;
                bool isEmailActive = false;
                int emailPreference = 2;

                if ( arenaPerson.PersonEmail.Count > 0 )
                {
                    int minOrder = arenaPerson.PersonEmail.Min( pe => pe.email_order );

                    PersonEmail arenaPrimaryEmail = arenaPerson.PersonEmail.FirstOrDefault( e => e.email_order == minOrder );
                    primaryEmailAddress = arenaPrimaryEmail.email;
                    emailNote = arenaPrimaryEmail.notes;
                    isEmailActive = arenaPrimaryEmail.active;

                    if ( isEmailActive )
                    {
                        if ( arenaPrimaryEmail.allow_bulk_mail )
                        {
                            emailPreference = 0;
                        }
                        else
                        {
                            emailPreference = 1;
                        }
                    }
                }

                string foreignId = arenaPerson.person_id.ToString();

                int? photoId = null;

                if ( arenaPerson.blob_id != null && PhotoUploadEnabled() )
                {
                    photoId = SavePersonPhoto( arenaPerson.Blob );
                }

                rockPersonId = rockPersonMap.Save( false, recordTypeValueId: recordTypeValueId, recordStatusValueId: recordStatusValueId, recordStatusReasonValueId: recordStatusReasonId, isDeceased: isDeceased,
                    connectionStatusValueId: connectionStatusValueID, titleValueId: titleValueId, firstName: arenaPerson.first_name, nickName: arenaPerson.nick_name, middleName: arenaPerson.middle_name,
                    lastName: arenaPerson.last_name, suffixValueId: suffixValueId, birthDay: birthDay, birthMonth: birthMonth, birthYear: birthYear, gender: gender, maritalStatusValueId: maritalStatusValueId,
                    anniversaryDate: anniversaryDate, graduationDate: graduationDate, givingGroupId: givingGroupId, email: primaryEmailAddress, isEmailActive: isEmailActive, emailNote: emailNote, emailPreference: emailPreference,
                    foreignId: foreignId, photoId: photoId );

                if ( rockPersonId == null )
                {
                    OnExportAttemptCompleted( identifier, false );
                    return;
                }

                int? personAliasId = rockPersonMap.SaveNewPersonAlias( (int)rockPersonId );

                RockMaps.GroupMap rockGroupMap = new RockMaps.GroupMap( Service );
                int familyMemberRoleId;

                if ( arenaPerson.FamilyMember.FirstOrDefault().role_luid == ARENA_ADULT_ROLE_LUID )
                {
                    familyMemberRoleId = rockGroupMap.GetFamilyAdultGroupRoleId();
                }
                else
                {
                    familyMemberRoleId = rockGroupMap.GetFamilyChildGroupRoleId();
                }

                rockGroupMap.SaveGroupMember( (int) rockFamilyId, (int) rockPersonId, familyMemberRoleId, 1 );

                rockGroupMap.SaveKnownRelationshipsGroup( (int)rockPersonId );
                rockGroupMap.SaveImpliedRelationshipsGroup( (int)rockPersonId );

                int? individualRockFamilyId = null;
                foreach ( var personAddress in arenaPerson.PersonAddress )
                {

                    if ( AddressIsFamilyAddress( arenaPerson.FamilyMember.FirstOrDefault().family_id, personAddress.address_id ) )
                    {
                        //either a single member family or Arena address found on multiple people in the family.
                        AddFamilyLocation( (int) rockFamilyId, personAddress );
                    }
                    else
                    {
                        //multiple person family and address only listed for this person
                        if ( individualRockFamilyId == null )
                        {

                            individualRockFamilyId = AddIndividualFamily( (int) rockPersonId, arenaPerson,  (int) rockFamilyId );
                        }
                        AddFamilyLocation( (int) individualRockFamilyId, personAddress );
                    }
                }

                foreach ( var phone in arenaPerson.PersonPhone.Where(p => !String.IsNullOrWhiteSpace(p.phone_number) ) )
                {
                    int? personPhone = SavePersonPhone( (int) rockPersonId, phone );
                }

            }
            else
            {
                rockPersonId = (int?)rockPerson["Id"];
            }

            if ( rockPersonId != null )
            {
                OnExportAttemptCompleted( identifier, true, rockPersonId, this.GetType() );
            }
            else
            {
                OnExportAttemptCompleted( identifier, false, mapType: this.GetType() );
            }
        }
示例#2
0
        private int? AddIndividualFamily( int? rockPersonId, Person arenaPerson, int modelRockFamilyId )
        {
            RockMaps.GroupMap groupMap = new RockMaps.GroupMap( Service );

            Dictionary<string, object> modelFamily = groupMap.GetGroupById( modelRockFamilyId );
            var modelFamilyMembers = groupMap.GetGroupMemberByGroupIdPersonId( (int)modelFamily["Id"], (int)rockPersonId );

            int roleId = 0;

            if ( modelFamilyMembers != null && modelFamilyMembers.Count > 0 )
            {
                roleId = (int)modelFamilyMembers.First().Value["GroupRoleId"];
            }

            string groupDescription = string.Format( "Individual \"family\" for {0} {1}", arenaPerson.nick_name, arenaPerson.last_name );
            int? individualFamilyId = groupMap.SaveFamily( (int?)modelFamily["CampusId"], modelFamily["Name"].ToString(), description: groupDescription );

            if ( individualFamilyId != null )
            {
                groupMap.SaveGroupMember( (int)individualFamilyId, (int)rockPersonId, roleId );
            }

            return individualFamilyId;
        }