コード例 #1
0
        /// <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" )
            {
                if ( ppPerson.PersonId.HasValue && !FamilyMembers.Any( m => m.Id == ppPerson.PersonId.Value ) )
                {
                    var rockContext = new RockContext();
                    var person = new PersonService( rockContext ).Get( ppPerson.PersonId.Value );
                    if ( person != null )
                    {
                        var familyMember = new FamilyMember();
                        familyMember.SetValuesFromPerson( person );

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

                        var existingFamilyRoles = new GroupMemberService( rockContext ).Queryable( "GroupRole" )
                            .Where( m => m.PersonId == person.Id && familyRoleIds.Contains( m.GroupRoleId ) )
                            .OrderBy( m => m.GroupRole.Order )
                            .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.NickName = 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 );
            }

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

            confirmExit.Enabled = true;

            hfActiveTab.Value = string.Empty;

            modalAddPerson.Hide();

            BindMembers();
        }
コード例 #2
0
        /// <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" )
            {
                if ( ppPerson.PersonId.HasValue )
                {
                    var existingfamilyMember = FamilyMembers.Where( m => m.Id == ppPerson.PersonId.Value ).FirstOrDefault();
                    if ( existingfamilyMember != null )
                    {
                        existingfamilyMember.Removed = false;
                    }
                    else
                    {
                        var rockContext = new RockContext();
                        var person = new PersonService( rockContext ).Get( ppPerson.PersonId.Value );
                        if ( person != null )
                        {
                            var familyMember = new FamilyMember();
                            familyMember.SetValuesFromPerson( person );

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

                            var existingFamilyRoles = new GroupMemberService( rockContext ).Queryable( "GroupRole" )
                                .Where( m => m.PersonId == person.Id && familyRoleIds.Contains( m.GroupRoleId ) )
                                .OrderBy( m => m.GroupRole.Order )
                                .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.TitleValueId = ddlNewPersonTitle.SelectedValueAsId();
                familyMember.FirstName = tbNewPersonFirstName.Text;
                familyMember.NickName = tbNewPersonFirstName.Text;
                familyMember.LastName = tbNewPersonLastName.Text;
                familyMember.SuffixValueId = ddlNewPersonSuffix.SelectedValueAsId();
                familyMember.Gender = rblNewPersonGender.SelectedValueAsEnum<Gender>();
                familyMember.MaritalStatusValueId = ddlNewPersonMaritalStatus.SelectedValueAsInt();
                DateTime? birthdate = dpNewPersonBirthDate.SelectedDate;
                if ( birthdate.HasValue )
                {
                    // If setting a future birthdate, subtract a century until birthdate is not greater than today.
                    var today = RockDateTime.Today;
                    while ( birthdate.Value.CompareTo( today ) > 0 )
                    {
                        birthdate = birthdate.Value.AddYears( -100 );
                    }
                }
                familyMember.BirthDate = birthdate;
                familyMember.GradeOffset = ddlGradePicker.SelectedValueAsInt();
                familyMember.ConnectionStatusValueId = ddlNewPersonConnectionStatus.SelectedValueAsId();
                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 );
            }

            ppPerson.Required = false;
            tbNewPersonFirstName.Required = false;
            tbNewPersonLastName.Required = false;
            rblNewPersonRole.Required = false;
            rblNewPersonGender.Required = false;
            ddlNewPersonConnectionStatus.Required = false;

            confirmExit.Enabled = true;

            hfActiveTab.Value = string.Empty;

            modalAddPerson.Hide();

            BindMembers();
        }