/// <summary>
        /// Handles the SaveClick event of the modalAddPerson control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        void modalAddPerson_SaveClick(object sender, EventArgs e)
        {
            if (hfActiveTab.Value == "Existing")
            {
                int?personId = ppExistingPerson.PersonId;
                if (personId.HasValue)
                {
                    using (new UnitOfWorkScope())
                    {
                        var person = new PersonService().Get(personId.Value);
                        if (person != null)
                        {
                            var familyMember = new FamilyMember();
                            familyMember.SetValuesFromPerson(person);

                            var familyRoleIds = familyRoles.Select(r => r.Id).ToList();

                            var existingFamilyRoles = new GroupMemberService().Queryable("GroupRole")
                                                      .Where(m => m.PersonId == person.Id && familyRoleIds.Contains(m.GroupRoleId))
                                                      .OrderBy(m => m.GroupRole.SortOrder)
                                                      .ToList();

                            var existingRole = existingFamilyRoles.Select(m => m.GroupRole).FirstOrDefault();
                            if (existingRole != null)
                            {
                                familyMember.RoleGuid = existingRole.Guid;
                                familyMember.RoleName = existingRole.Name;
                            }

                            familyMember.ExistingFamilyMember    = existingFamilyRoles.Any(r => r.GroupId == _family.Id);
                            familyMember.RemoveFromOtherFamilies = cbRemoveOtherFamilies.Checked;

                            FamilyMembers.Add(familyMember);
                        }
                    }
                }
            }
            else
            {
                var familyMember = new FamilyMember();
                familyMember.FirstName = tbNewPersonFirstName.Text;
                familyMember.LastName  = tbNewPersonLastName.Text;
                familyMember.Gender    = ddlNewPersonGender.SelectedValueAsEnum <Gender>();
                familyMember.BirthDate = dpNewPersonBirthDate.SelectedDate;
                var role = familyRoles.Where(r => r.Id == (rblNewPersonRole.SelectedValueAsInt() ?? 0)).FirstOrDefault();
                if (role != null)
                {
                    familyMember.RoleGuid = role.Guid;
                    familyMember.RoleName = role.Name;
                }
                FamilyMembers.Add(familyMember);
            }

            tbNewPersonFirstName.Required = false;
            tbNewPersonLastName.Required  = false;

            confirmExit.Enabled = true;

            BindMembers();
        }
Example #2
0
        private void AddFamilyMember()
        {
            var familyGroupType = GroupTypeCache.GetFamilyGroupType();

            if (familyGroupType != null && familyGroupType.DefaultGroupRoleId != null)
            {
                int recordTypePersonId    = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON.AsGuid()).Id;
                int recordStatusActiveId  = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE.AsGuid()).Id;
                var ConnectionStatusValue = DefinedValueCache.Read(GetAttributeValue("DefaultConnectionStatus").AsGuid());

                var person = new Person();
                person.Guid = Guid.NewGuid();
                person.RecordTypeValueId   = recordTypePersonId;
                person.RecordStatusValueId = recordStatusActiveId;
                person.Gender = Gender.Unknown;
                person.ConnectionStatusValueId = (ConnectionStatusValue != null) ? ConnectionStatusValue.Id : (int?)null;

                var familyMember = new GroupMember();
                familyMember.GroupMemberStatus = GroupMemberStatus.Active;
                familyMember.GroupRoleId       = familyGroupType.DefaultGroupRoleId.Value;
                familyMember.Person            = person;

                FamilyMembers.Add(familyMember);
            }
        }