protected int GetPersonIdFromInputData() { string sFirstName = tbFirstName.Text; string sLastName = tbLastName.Text; string sEmail = tbEmail.Text; string sAddress = tbAddress1.Text; string sCity = tbCity.Text; string sState = tbState.Text; string sZip = tbZip.Text; string sPhone = tbPhone.Text; PersonCollection personCollection = new PersonCollection(); personCollection.LoadByEmail(sEmail); int iFoundPersonId = -1; foreach (Person person in personCollection) { PersonPhone phoneSearch = new PersonPhone(person.PersonID, FormatPhone(sPhone)); if ((phoneSearch.PersonID == person.PersonID) && (person.LastName.ToLower() == sLastName.ToLower())) { this.currentAddress = person.Addresses.FindByType(41); if(this.currentAddress.Address.PostalCode.Substring(0,5) == sZip ) { iFoundPersonId = person.PersonID; } } } if (iFoundPersonId > 0) { //person in the db //easy ride... } else { //create the family for the person Family family = new Family(); family.OrganizationID = CurrentArenaContext.Organization.OrganizationID; family.FamilyName = sLastName + " Family"; //add person to the family FamilyMember familyMember = new FamilyMember(); family.FamilyMembers.Add(familyMember); // // Ensure some of the basics are set correctly. // if ((familyMember.Campus == null || familyMember.Campus.CampusId == -1) && NewPersonCampusSetting != -1) familyMember.Campus = new Campus(NewPersonCampusSetting); if (familyMember.MemberStatus == null || familyMember.MemberStatus.LookupID == -1) familyMember.MemberStatus = new Lookup(NewPersonStatusSetting); if (familyMember.RecordStatus == Arena.Enums.RecordStatus.Undefined) familyMember.RecordStatus = Arena.Enums.RecordStatus.Pending; //add person to the db familyMember.FirstName = sFirstName; familyMember.FirstName = sFirstName; familyMember.LastName = sLastName; familyMember.FamilyRole = new Lookup(new Guid("e410e1a6-8715-4bfb-bf03-1cd18051f815")); familyMember.Gender = Arena.Enums.Gender.Unknown; familyMember.MaritalStatus = new Lookup(new Guid("9C000CF2-677B-4725-981E-BD555FDAFB30")); //add email to db and person to email PersonEmail personEmail = new PersonEmail(); personEmail.Email = sEmail; personEmail.Active = true; familyMember.Emails.Add(personEmail); //add address to db and person to address PersonAddress personAddress = new PersonAddress(); personAddress.Address.StreetLine1 = sAddress; personAddress.Address.City = sCity; personAddress.Address.State = sState; personAddress.Address.PostalCode = sZip; personAddress.AddressType = new Lookup(41); personAddress.Address.Standardize(); this.currentAddress = personAddress; familyMember.Addresses.Add(personAddress); //add phone to db and person to phone PersonPhone personPhone = new PersonPhone(); personPhone.PhoneType = new Lookup(new Guid("f2a0fba2-d5ab-421f-a5ab-0c67db6fd72e")); familyMember.Phones.Add(personPhone); personPhone.Number = FormatPhone(sPhone); //Save All family.Save(ModuleUserName); familyMember.Save(CurrentOrganization.OrganizationID, ModuleUserName, true); familyMember.SaveEmails(CurrentPortal.OrganizationID, ModuleUserName); familyMember.SaveAddresses(CurrentPortal.OrganizationID, ModuleUserName); familyMember.SavePhones(CurrentPortal.OrganizationID, ModuleUserName); familyMember.Save(CurrentUser.Identity.Name); iFoundPersonId = familyMember.PersonID; } return iFoundPersonId; }