/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid) { if (ViewMode == VIEW_MODE_EDIT) { ChangeRequest changeRequest = new ChangeRequest { EntityId = Person.Id, EntityTypeId = EntityTypeCache.Get(typeof(Person)).Id, RequestorAliasId = CurrentPersonAliasId ?? 0 }; foreach (int attributeId in AttributeList) { var attribute = AttributeCache.Get(attributeId); if (Person != null && attribute.IsAuthorized(Authorization.EDIT, CurrentPerson)) { Control attributeControl = fsAttributes.FindControl(string.Format("attribute_field_{0}", attribute.Id)); if (attributeControl != null) { Person.SetAttributeValue(attribute.Key, attribute.FieldType.Field.GetEditValue(attributeControl, attribute.QualifierValues)); } } } changeRequest.EvaluateAttributes(Person); if (changeRequest.ChangeRecords.Any()) { var rockContext = new RockContext(); ChangeRequestService changeRequestService = new ChangeRequestService(rockContext); changeRequestService.Add(changeRequest); rockContext.SaveChanges(); List <string> errors; changeRequest.CompleteChanges(rockContext, out errors); } } else if (ViewMode == VIEW_MODE_ORDER && _canAdministrate) { // Split and delineate again to remove trailing delimiter var attributeOrder = hfAttributeOrder.Value.SplitDelimitedValues().ToList().AsDelimited("|"); SetAttributeValue("AttributeOrder", attributeOrder); SaveAttributeValues(); BindData(); } ViewMode = VIEW_MODE_VIEW; CreateControls(false); } }
protected void btnSave_Click(object sender, EventArgs e) { RockContext rockContext = new RockContext(); var person = GetPerson(); var personAliasEntityType = EntityTypeCache.Get(typeof(PersonAlias)); var changeRequest = new ChangeRequest { EntityTypeId = personAliasEntityType.Id, EntityId = person.PrimaryAliasId ?? 0, RequestorAliasId = CurrentPersonAliasId ?? 0, RequestorComment = tbComments.Text }; changeRequest.EvaluatePropertyChange(person, "PhotoId", iuPhoto.BinaryFileId); changeRequest.EvaluatePropertyChange(person, "TitleValue", DefinedValueCache.Get(ddlTitle.SelectedValueAsInt() ?? 0)); changeRequest.EvaluatePropertyChange(person, "FirstName", tbFirstName.Text); changeRequest.EvaluatePropertyChange(person, "NickName", tbNickName.Text); changeRequest.EvaluatePropertyChange(person, "MiddleName", tbMiddleName.Text); changeRequest.EvaluatePropertyChange(person, "LastName", tbLastName.Text); changeRequest.EvaluatePropertyChange(person, "SuffixValue", DefinedValueCache.Get(ddlSuffix.SelectedValueAsInt() ?? 0)); var families = person.GetFamilies(); if (families.Count() == 1) { var groupMember = person.PrimaryFamily.Members.Where(gm => gm.PersonId == person.Id).FirstOrDefault(); if (groupMember != null) { GroupTypeRole groupTypeRole = null; GroupTypeRoleService groupTypeRoleService = new GroupTypeRoleService(rockContext); if (ddlFamilyRole.SelectedValue == "A") { groupTypeRole = groupTypeRoleService.Get(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid()); } else if (ddlFamilyRole.SelectedValue == "C") { groupTypeRole = groupTypeRoleService.Get(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD.AsGuid()); } changeRequest.EvaluatePropertyChange(groupMember, "GroupRole", groupTypeRole, true); } } //Evaluate PhoneNumbers var phoneNumberTypeIds = new List <int>(); bool smsSelected = false; foreach (RepeaterItem item in rContactInfo.Items) { HiddenField hfPhoneType = item.FindControl("hfPhoneType") as HiddenField; PhoneNumberBox pnbPhone = item.FindControl("pnbPhone") as PhoneNumberBox; CheckBox cbUnlisted = item.FindControl("cbUnlisted") as CheckBox; CheckBox cbSms = item.FindControl("cbSms") as CheckBox; if (hfPhoneType != null && pnbPhone != null && cbSms != null && cbUnlisted != null) { int phoneNumberTypeId; if (int.TryParse(hfPhoneType.Value, out phoneNumberTypeId)) { var phoneNumber = person.PhoneNumbers.FirstOrDefault(n => n.NumberTypeValueId == phoneNumberTypeId); string oldPhoneNumber = string.Empty; if (phoneNumber == null && pnbPhone.Number.IsNotNullOrWhiteSpace()) //Add number { phoneNumber = new PhoneNumber { PersonId = person.Id, NumberTypeValueId = phoneNumberTypeId, CountryCode = PhoneNumber.CleanNumber(pnbPhone.CountryCode), IsMessagingEnabled = !smsSelected && cbSms.Checked, Number = PhoneNumber.CleanNumber(pnbPhone.Number) }; var phoneComment = string.Format("{0}: {1}.", DefinedValueCache.Get(phoneNumberTypeId).Value, pnbPhone.Number); changeRequest.AddEntity(phoneNumber, rockContext, true, phoneComment); } else if (phoneNumber != null && pnbPhone.Text.IsNullOrWhiteSpace()) // delete number { var phoneComment = string.Format("{0}: {1}.", phoneNumber.NumberTypeValue.Value, phoneNumber.NumberFormatted); changeRequest.DeleteEntity(phoneNumber, true, phoneComment); } else if (phoneNumber != null && pnbPhone.Text.IsNotNullOrWhiteSpace()) // update number { changeRequest.EvaluatePropertyChange(phoneNumber, "Number", PhoneNumber.CleanNumber(pnbPhone.Number), true); changeRequest.EvaluatePropertyChange(phoneNumber, "IsMessagingEnabled", (!smsSelected && cbSms.Checked), true); changeRequest.EvaluatePropertyChange(phoneNumber, "IsUnlisted", cbUnlisted.Checked, true); } if (hfPhoneType.Value.AsInteger() == DefinedValueCache.GetId(Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_MOBILE.AsGuid())) { var validationInfo = ValidateMobilePhoneNumber(PhoneNumber.CleanNumber(pnbPhone.Number)); if (validationInfo.IsNotNullOrWhiteSpace()) { changeRequest.RequestorComment += "<h4>Dynamically Generated Warnings:</h4>" + validationInfo; } } } } } changeRequest.EvaluatePropertyChange(person, "Email", tbEmail.Text); changeRequest.EvaluatePropertyChange(person, "IsEmailActive", cbIsEmailActive.Checked); changeRequest.EvaluatePropertyChange(person, "EmailPreference", rblEmailPreference.SelectedValueAsEnum <EmailPreference>()); changeRequest.EvaluatePropertyChange(person, "CommunicationPreference", rblCommunicationPreference.SelectedValueAsEnum <CommunicationType>()); var birthday = bpBirthday.SelectedDate; if (birthday.HasValue) { changeRequest.EvaluatePropertyChange(person, "BirthMonth", birthday.Value.Month); changeRequest.EvaluatePropertyChange(person, "BirthDay", birthday.Value.Day); if (birthday.Value.Year != DateTime.MinValue.Year) { changeRequest.EvaluatePropertyChange(person, "BirthYear", birthday.Value.Year); } else { int?year = null; changeRequest.EvaluatePropertyChange(person, "BirthYear", year); } } changeRequest.EvaluatePropertyChange(person, "Gender", ddlGender.SelectedValueAsEnum <Gender>()); changeRequest.EvaluatePropertyChange(person, "MaritalStatusValue", DefinedValueCache.Get(ddlMaritalStatus.SelectedValueAsInt() ?? 0)); changeRequest.EvaluatePropertyChange(person, "AnniversaryDate", dpAnniversaryDate.SelectedDate); changeRequest.EvaluatePropertyChange(person, "GraduationYear", ypGraduation.SelectedYear); var groupEntity = EntityTypeCache.Get(typeof(Group)); var groupLocationEntity = EntityTypeCache.Get(typeof(GroupLocation)); var family = person.GetFamily(); var familyChangeRequest = new ChangeRequest() { EntityTypeId = groupEntity.Id, EntityId = family.Id, RequestorAliasId = CurrentPersonAliasId ?? 0 }; familyChangeRequest.EvaluatePropertyChange(family, "Campus", CampusCache.Get(ddlCampus.SelectedValueAsInt() ?? 0)); var currentLocation = person.GetHomeLocation(); Location location = new Location { Street1 = acAddress.Street1, Street2 = acAddress.Street2, City = acAddress.City, State = acAddress.State, PostalCode = acAddress.PostalCode, }; var globalAttributesCache = GlobalAttributesCache.Get(); location.Country = globalAttributesCache.OrganizationCountry; location.Country = string.IsNullOrWhiteSpace(location.Country) ? "US" : location.Country; if ((currentLocation == null && location.Street1.IsNotNullOrWhiteSpace()) || (currentLocation != null && currentLocation.Street1 != location.Street1)) { LocationService locationService = new LocationService(rockContext); locationService.Add(location); rockContext.SaveChanges(); var previousLocationType = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_PREVIOUS.AsGuid()); var homeLocationType = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid()); GroupLocation groupLocation = new GroupLocation { CreatedByPersonAliasId = CurrentPersonAliasId, ModifiedByPersonAliasId = CurrentPersonAliasId, GroupId = family.Id, LocationId = location.Id, GroupLocationTypeValueId = homeLocationType.Id, IsMailingLocation = true, IsMappedLocation = true }; var newGroupLocation = familyChangeRequest.AddEntity(groupLocation, rockContext, true, location.ToString()); var homelocations = family.GroupLocations.Where(gl => gl.GroupLocationTypeValueId == homeLocationType.Id); foreach (var homelocation in homelocations) { familyChangeRequest.EvaluatePropertyChange( homelocation, "GroupLocationTypeValue", previousLocationType, true, homelocation.Location.ToString()); familyChangeRequest.EvaluatePropertyChange( homelocation, "IsMailingLocation", false, true, homelocation.Location.ToString()); } } //Adding a new family member if (pAddPerson.SelectedValue.HasValue) { PersonService personService = new PersonService(rockContext); var insertPerson = personService.Get(pAddPerson.SelectedValue.Value); if (insertPerson != null) { GroupMemberService groupMemberService = new GroupMemberService(rockContext); var familyGroupTypeId = GroupTypeCache.Get(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid()).Id; //Remove all other group members if (cbRemovePerson.Checked) { var members = groupMemberService.Queryable() .Where(m => m.PersonId == pAddPerson.SelectedValue.Value && m.Group.GroupTypeId == familyGroupTypeId); foreach (var member in members) { var comment = string.Format("Removed {0} from {1}", insertPerson.FullName, member.Group.Name); familyChangeRequest.DeleteEntity(member, true, comment); } } var personFamilies = person.GetFamilies().ToList(); GroupTypeRoleService groupTypeRoleService = new GroupTypeRoleService(rockContext); var roleId = groupTypeRoleService.Get(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid()).Id; if (insertPerson.Age.HasValue && insertPerson.Age.Value < 18) { roleId = groupTypeRoleService.Get(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD.AsGuid()).Id; } foreach (var personFamily in personFamilies) { //Make a new group member GroupMember familyMember = new GroupMember { PersonId = pAddPerson.SelectedValue.Value, GroupId = personFamily.Id, GroupMemberStatus = GroupMemberStatus.Active, Guid = Guid.NewGuid(), GroupRoleId = roleId }; var insertComment = string.Format("Added {0} to {1}", insertPerson.FullName, personFamily.Name); familyChangeRequest.AddEntity(familyMember, rockContext, true, insertComment); } } } bool autoApply = CanAutoApply(person); List <string> errors; if (changeRequest.ChangeRecords.Any() || (!familyChangeRequest.ChangeRecords.Any() && tbComments.Text.IsNotNullOrWhiteSpace())) { ChangeRequestService changeRequestService = new ChangeRequestService(rockContext); changeRequestService.Add(changeRequest); rockContext.SaveChanges(); if (autoApply) { changeRequest.CompleteChanges(rockContext, out errors); } changeRequest.LaunchWorkflow(GetAttributeValue("Workflow").AsGuidOrNull()); } if (familyChangeRequest.ChangeRecords.Any()) { familyChangeRequest.RequestorComment = tbComments.Text; ChangeRequestService changeRequestService = new ChangeRequestService(rockContext); changeRequestService.Add(familyChangeRequest); rockContext.SaveChanges(); if (autoApply) { familyChangeRequest.CompleteChanges(rockContext, out errors); } familyChangeRequest.LaunchWorkflow(GetAttributeValue("Workflow").AsGuidOrNull()); } if (autoApply) { NavigateToPerson(); } else { pnlMain.Visible = false; pnlNoPerson.Visible = false; pnlDone.Visible = true; } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { if (GetAttributeValue(AttributeKeys.DisplayTerms).AsBoolean() && !cbTOS.Checked) { nbTOS.Visible = true; return; } var rockContext = new RockContext(); var personService = new PersonService(rockContext); var person = GetPerson(personService); var personAliasEntityType = EntityTypeCache.Get(typeof(PersonAlias)); if (person.Id != 0) { var changeRequest = new ChangeRequest { EntityTypeId = personAliasEntityType.Id, EntityId = person.PrimaryAliasId ?? 0, RequestorAliasId = CurrentPersonAliasId ?? 0 }; if (person.PhotoId != imgPhoto.BinaryFileId) { changeRequest.EvaluatePropertyChange(person, "PhotoId", imgPhoto.BinaryFileId); if (person.Photo != null) { changeRequest.EvaluatePropertyChange(person.Photo, "IsTemporary", true, true); } } changeRequest.EvaluatePropertyChange(person, "TitleValue", DefinedValueCache.Get(ddlTitle.SelectedValueAsInt() ?? 0)); changeRequest.EvaluatePropertyChange(person, "FirstName", tbFirstName.Text); changeRequest.EvaluatePropertyChange(person, "NickName", tbNickName.Text); changeRequest.EvaluatePropertyChange(person, "LastName", tbLastName.Text); changeRequest.EvaluatePropertyChange(person, "SuffixValue", DefinedValueCache.Get(ddlSuffix.SelectedValueAsInt() ?? 0)); var birthMonth = person.BirthMonth; var birthDay = person.BirthDay; var birthYear = person.BirthYear; var birthday = bpBirthDay.SelectedDate; if (birthday.HasValue) { // If setting a future birth date, subtract a century until birth date is not greater than today. var today = RockDateTime.Today; while (birthday.Value.CompareTo(today) > 0) { birthday = birthday.Value.AddYears(-100); } changeRequest.EvaluatePropertyChange(person, "BirthMonth", birthday.Value.Month); changeRequest.EvaluatePropertyChange(person, "BirthDay", birthday.Value.Day); if (birthday.Value.Year != DateTime.MinValue.Year) { changeRequest.EvaluatePropertyChange(person, "BirthYear", birthday.Value.Year); } else { changeRequest.EvaluatePropertyChange(person, "BirthYear", ( int? )null); } } if (ddlGradePicker.Visible) { changeRequest.EvaluatePropertyChange(person, "GraduationYear", ypGraduation.SelectedYear); } changeRequest.EvaluatePropertyChange(person, "Gender", rblGender.SelectedValue.ConvertToEnum <Gender>()); var primaryFamilyMembers = person.GetFamilyMembers(true).Where(m => m.PersonId == person.Id).ToList(); foreach (var member in primaryFamilyMembers) { changeRequest.EvaluatePropertyChange(member, "GroupRoleId", rblRole.SelectedValue.AsInteger(), true); } var primaryFamily = person.GetFamily(rockContext); var familyChangeRequest = new ChangeRequest { EntityTypeId = EntityTypeCache.Get(typeof(Group)).Id, EntityId = primaryFamily.Id, RequestorAliasId = CurrentPersonAliasId ?? 0 }; // update campus bool showCampus = GetAttributeValue("ShowCampusSelector").AsBoolean(); if (showCampus) { // Only update campus for adults GroupTypeRoleService groupTypeRoleService = new GroupTypeRoleService(rockContext); var adultGuid = Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid(); var adultRole = groupTypeRoleService.Get(adultGuid); if (rblRole.SelectedValue.AsInteger() == adultRole.Id) { familyChangeRequest.EvaluatePropertyChange(primaryFamily, "CampusId", cpCampus.SelectedCampusId); } } //Evaluate PhoneNumbers bool showPhoneNumbers = GetAttributeValue("ShowPhoneNumbers").AsBoolean(); if (showPhoneNumbers) { var phoneNumberTypeIds = new List <int>(); var phoneNumbersScreen = new List <PhoneNumber>(); bool smsSelected = false; foreach (RepeaterItem item in rContactInfo.Items) { HiddenField hfPhoneType = item.FindControl("hfPhoneType") as HiddenField; PhoneNumberBox pnbPhone = item.FindControl("pnbPhone") as PhoneNumberBox; CheckBox cbUnlisted = item.FindControl("cbUnlisted") as CheckBox; CheckBox cbSms = item.FindControl("cbSms") as CheckBox; if (hfPhoneType != null && pnbPhone != null && cbSms != null && cbUnlisted != null) { int phoneNumberTypeId; if (int.TryParse(hfPhoneType.Value, out phoneNumberTypeId)) { var phoneNumberList = person.PhoneNumbers.Where(n => n.NumberTypeValueId == phoneNumberTypeId).ToList(); var phoneNumber = phoneNumberList.FirstOrDefault(pn => pn.Number == PhoneNumber.CleanNumber(pnbPhone.Number)); string oldPhoneNumber = string.Empty; if (phoneNumber == null && pnbPhone.Number.IsNotNullOrWhiteSpace()) //Add number { phoneNumber = new PhoneNumber { PersonId = person.Id, NumberTypeValueId = phoneNumberTypeId, CountryCode = PhoneNumber.CleanNumber(pnbPhone.CountryCode), IsMessagingEnabled = !smsSelected && cbSms.Checked, Number = PhoneNumber.CleanNumber(pnbPhone.Number) }; var phoneComment = string.Format("{0}: {1}.", DefinedValueCache.Get(phoneNumberTypeId).Value, pnbPhone.Number); changeRequest.AddEntity(phoneNumber, rockContext, true, phoneComment); phoneNumbersScreen.Add(phoneNumber); } else if (phoneNumber != null && pnbPhone.Text.IsNotNullOrWhiteSpace()) // update number { changeRequest.EvaluatePropertyChange(phoneNumber, "Number", PhoneNumber.CleanNumber(pnbPhone.Number), true); changeRequest.EvaluatePropertyChange(phoneNumber, "IsMessagingEnabled", (!smsSelected && cbSms.Checked), true); changeRequest.EvaluatePropertyChange(phoneNumber, "IsUnlisted", cbUnlisted.Checked, true); phoneNumbersScreen.Add(phoneNumber); } } } } //Remove old phone numbers or changed var phoneNumbersToRemove = person.PhoneNumbers .Where(n => !phoneNumbersScreen.Any(n2 => n2.Number == n.Number && n2.NumberTypeValueId == n.NumberTypeValueId)).ToList(); foreach (var number in phoneNumbersToRemove) { var phoneComment = string.Format("{0}: {1}.", number.NumberTypeValue.Value, number.NumberFormatted); changeRequest.DeleteEntity(number, true, phoneComment); } } changeRequest.EvaluatePropertyChange(person, "Email", tbEmail.Text.Trim()); changeRequest.EvaluatePropertyChange(person, "EmailPreference", rblEmailPreference.SelectedValueAsEnum <EmailPreference>()); changeRequest.EvaluatePropertyChange(person, "CommunicationPreference", rblCommunicationPreference.SelectedValueAsEnum <CommunicationType>()); // if they used the ImageEditor, and cropped it, the non-cropped file is still in BinaryFile. So clean it up if (imgPhoto.CropBinaryFileId.HasValue) { if (imgPhoto.CropBinaryFileId != person.PhotoId) { BinaryFileService binaryFileService = new BinaryFileService(rockContext); var binaryFile = binaryFileService.Get(imgPhoto.CropBinaryFileId.Value); if (binaryFile != null && binaryFile.IsTemporary) { string errorMessage; if (binaryFileService.CanDelete(binaryFile, out errorMessage)) { binaryFileService.Delete(binaryFile); rockContext.SaveChanges(); } } } } // save family information if (pnlAddress.Visible) { var currentLocation = person.GetHomeLocation(); Location location = new Location { Street1 = acAddress.Street1, Street2 = acAddress.Street2, City = acAddress.City, State = acAddress.State, PostalCode = acAddress.PostalCode, }; var globalAttributesCache = GlobalAttributesCache.Get(); location.Country = globalAttributesCache.OrganizationCountry; location.Country = string.IsNullOrWhiteSpace(location.Country) ? "US" : location.Country; if ((currentLocation == null && location.Street1.IsNotNullOrWhiteSpace()) || (currentLocation != null && currentLocation.Street1 != location.Street1)) { LocationService locationService = new LocationService(rockContext); locationService.Add(location); rockContext.SaveChanges(); var previousLocationType = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_PREVIOUS.AsGuid()); var homeLocationType = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid()); GroupLocation groupLocation = new GroupLocation { CreatedByPersonAliasId = CurrentPersonAliasId, ModifiedByPersonAliasId = CurrentPersonAliasId, GroupId = primaryFamily.Id, LocationId = location.Id, GroupLocationTypeValueId = homeLocationType.Id, IsMailingLocation = true, IsMappedLocation = true }; var newGroupLocation = familyChangeRequest.AddEntity(groupLocation, rockContext, true, location.ToString()); var homelocations = primaryFamily.GroupLocations.Where(gl => gl.GroupLocationTypeValueId == homeLocationType.Id); foreach (var homelocation in homelocations) { familyChangeRequest.EvaluatePropertyChange( homelocation, "GroupLocationTypeValue", previousLocationType, true, homelocation.Location.ToString()); familyChangeRequest.EvaluatePropertyChange( homelocation, "IsMailingLocation", false, true, homelocation.Location.ToString()); } } } // Handle both Child and Adult attributes together here var attributeGuids = GetAttributeValue(AttributeKeys.PersonAttributesAdult).SplitDelimitedValues().AsGuidList(); attributeGuids.AddRange(GetAttributeValue(AttributeKeys.PersonAttributesChild).SplitDelimitedValues().AsGuidList()); if (attributeGuids.Count > 0) { person.LoadAttributes(); Helper.GetEditValues(phAttributes, person); changeRequest.EvaluateAttributes(person); } List <string> errors; if (changeRequest.ChangeRecords.Any() || (!familyChangeRequest.ChangeRecords.Any() && tbComments.Text.IsNotNullOrWhiteSpace())) { changeRequest.RequestorComment = tbComments.Text; ChangeRequestService changeRequestService = new ChangeRequestService(rockContext); changeRequestService.Add(changeRequest); rockContext.SaveChanges(); changeRequest.CompleteChanges(rockContext, out errors); } if (familyChangeRequest.ChangeRecords.Any()) { familyChangeRequest.RequestorComment = tbComments.Text; ChangeRequestService changeRequestService = new ChangeRequestService(rockContext); changeRequestService.Add(familyChangeRequest); rockContext.SaveChanges(); familyChangeRequest.CompleteChanges(rockContext, out errors); } } else { var primaryFamily = CurrentPerson.GetFamily(rockContext); person.PhotoId = imgPhoto.BinaryFileId; if (imgPhoto.BinaryFileId.HasValue) { BinaryFileService binaryFileService = new BinaryFileService(rockContext); var binaryFile = binaryFileService.Get(imgPhoto.BinaryFileId.Value); binaryFile.IsTemporary = false; } person.FirstName = tbFirstName.Text; person.NickName = tbNickName.Text; person.LastName = tbLastName.Text; person.TitleValueId = ddlTitle.SelectedValue.AsIntegerOrNull(); person.SuffixValueId = ddlSuffix.SelectedValue.AsIntegerOrNull(); var birthday = bpBirthDay.SelectedDate; if (birthday.HasValue) { // If setting a future birth date, subtract a century until birth date is not greater than today. var today = RockDateTime.Today; while (birthday.Value.CompareTo(today) > 0) { birthday = birthday.Value.AddYears(-100); } person.BirthMonth = birthday.Value.Month; person.BirthDay = birthday.Value.Day; if (birthday.Value.Year != DateTime.MinValue.Year) { person.BirthYear = birthday.Value.Year; } else { person.BirthYear = null; } } person.Gender = rblGender.SelectedValue.ConvertToEnum <Gender>(); person.Email = tbEmail.Text; person.EmailPreference = rblEmailPreference.SelectedValue.ConvertToEnum <EmailPreference>(); if (ddlGradePicker.Visible) { person.GraduationYear = ypGraduation.SelectedYear; } GroupMember groupMember = new GroupMember { PersonId = person.Id, GroupId = primaryFamily.Id, GroupRoleId = rblRole.SelectedValue.AsInteger() }; PersonService.AddPersonToFamily(person, true, primaryFamily.Id, rblRole.SelectedValue.AsInteger(), rockContext); PhoneNumberService phoneNumberService = new PhoneNumberService(rockContext); foreach (RepeaterItem item in rContactInfo.Items) { HiddenField hfPhoneType = item.FindControl("hfPhoneType") as HiddenField; PhoneNumberBox pnbPhone = item.FindControl("pnbPhone") as PhoneNumberBox; CheckBox cbUnlisted = item.FindControl("cbUnlisted") as CheckBox; CheckBox cbSms = item.FindControl("cbSms") as CheckBox; if (hfPhoneType != null && pnbPhone != null && cbSms != null && cbUnlisted != null && pnbPhone.Number.IsNotNullOrWhiteSpace()) { int phoneNumberTypeId; if (int.TryParse(hfPhoneType.Value, out phoneNumberTypeId)) { var phoneNumber = new PhoneNumber { PersonId = person.Id, NumberTypeValueId = phoneNumberTypeId, CountryCode = PhoneNumber.CleanNumber(pnbPhone.CountryCode), IsMessagingEnabled = cbSms.Checked, Number = PhoneNumber.CleanNumber(pnbPhone.Number) }; phoneNumberService.Add(phoneNumber); } } } rockContext.SaveChanges(); var changeRequest = new ChangeRequest { EntityTypeId = personAliasEntityType.Id, EntityId = person.PrimaryAliasId ?? 0, RequestorAliasId = CurrentPersonAliasId ?? 0, RequestorComment = "Added as new person from My Account." }; if (tbComments.Text.IsNotNullOrWhiteSpace()) { changeRequest.RequestorComment += "<br><br>Comment: " + tbComments.Text; } ChangeRequestService changeRequestService = new ChangeRequestService(rockContext); changeRequestService.Add(changeRequest); rockContext.SaveChanges(); List <string> errors; changeRequest.CompleteChanges(rockContext, out errors); } NavigateToParentPage(); }