Пример #1
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        private void ShowDetail()
        {
            var rockContext = new RockContext();
            var groupMemberService = new GroupMemberService( rockContext );
            var attributeValueService = new AttributeValueService( rockContext );

            if ( CurrentPerson != null )
            {
                var personId = CurrentPerson.Id;

                // Setup Image
                string imgTag = Rock.Model.Person.GetPersonPhotoImageTag( CurrentPerson, 200, 200 );
                if ( CurrentPerson.PhotoId.HasValue )
                {
                    lImage.Text = string.Format( "<a href='{0}'>{1}</a>", CurrentPerson.PhotoUrl, imgTag );
                }
                else
                {
                    lImage.Text = imgTag;
                }

                // Person Info
                lName.Text = CurrentPerson.FullName;
                if ( CurrentPerson.BirthDate.HasValue )
                {
                    lAge.Text = string.Format( "{0}<small>({1})</small><br/>", CurrentPerson.FormatAge(), CurrentPerson.BirthYear != DateTime.MinValue.Year ? CurrentPerson.BirthDate.Value.ToShortDateString() : CurrentPerson.BirthDate.Value.ToMonthDayString() );
                }

                lGender.Text = CurrentPerson.Gender != Gender.Unknown ? CurrentPerson.Gender.ToString() : string.Empty;
                lGrade.Text = CurrentPerson.GradeFormatted;
                lMaritalStatus.Text = CurrentPerson.MaritalStatusValueId.DefinedValue();
                if ( CurrentPerson.AnniversaryDate.HasValue )
                {
                    lMaritalStatus.Text += string.Format( " {0} yrs <small>({1})</small>", CurrentPerson.AnniversaryDate.Value.Age(), CurrentPerson.AnniversaryDate.Value.ToMonthDayString() );
                }

                if ( CurrentPerson.GetFamilies().Count() > 1 )
                {
                    ddlGroup.Visible = true;
                }

                // Contact Info
                if ( CurrentPerson.PhoneNumbers != null )
                {
                    var selectedPhoneTypeGuids = GetAttributeValue( "PhoneNumbers" ).Split( ',' ).AsGuidList();
                    rptPhones.DataSource = CurrentPerson.PhoneNumbers.Where( pn => selectedPhoneTypeGuids.Contains( pn.NumberTypeValue.Guid ) ).ToList();
                    rptPhones.DataBind();
                }

                lEmail.Text = CurrentPerson.Email;

                // Person Attributes
                List<Guid> attributeGuidList = GetPersonAttributeGuids( personId );
                CurrentPerson.LoadAttributes();
                rptPersonAttributes.DataSource = CurrentPerson.Attributes.Where( a =>
                     attributeGuidList.Contains( a.Value.Guid ) )
                    .Select( a => new
                    {
                        Name = a.Value.Name,
                        Value = a.Value.FieldType.Field.FormatValue( null, CurrentPerson.GetAttributeValue( a.Key ), a.Value.QualifierValues, a.Value.FieldType.Class == typeof( Rock.Field.Types.ImageFieldType ).FullName )
                    } )
                    .OrderBy( av => av.Name )
                    .ToList()
                    .Where( av => !String.IsNullOrWhiteSpace( av.Value ) );
                rptPersonAttributes.DataBind();

                // Families
                if ( GetAttributeValue( "ShowFamilyMembers" ).AsBoolean() )
                {
                    if ( ddlGroup.SelectedValueAsId().HasValue )
                    {
                        var group = new GroupService( rockContext ).Get( ddlGroup.SelectedValueAsId().Value );
                        if ( group != null )
                        {

                            // Family Name
                            lGroupName.Text = group.Name;

                            // Family Address
                            Guid? locationTypeGuid = GetAttributeValue( "AddressType" ).AsGuidOrNull();
                            if ( locationTypeGuid.HasValue )
                            {
                                var addressTypeDv = DefinedValueCache.Read( locationTypeGuid.Value );

                                var familyGroupTypeGuid = Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuidOrNull();

                                if ( familyGroupTypeGuid.HasValue )
                                {
                                    var familyGroupType = GroupTypeCache.Read( familyGroupTypeGuid.Value );

                                    var address = new GroupLocationService( rockContext ).Queryable()
                                                        .Where( l => l.Group.GroupTypeId == familyGroupType.Id
                                                             && l.GroupLocationTypeValueId == addressTypeDv.Id
                                                             && l.Group.Members.Any( m => m.PersonId == CurrentPerson.Id )
                                                             && l.Group.Id == group.Id )
                                                        .Select( l => l.Location )
                                                        .FirstOrDefault();
                                    if ( address != null )
                                    {
                                        lAddress.Text = string.Format( "<div class='margin-b-md'><b>{0} Address</b><br />{1}</div>", addressTypeDv.Value, address.FormattedHtmlAddress );
                                    }
                                }
                            }

                            // Family Attributes
                            group.LoadAttributes();
                            List<Guid> familyAttributeGuidList = GetAttributeValue( "FamilyAttributes" ).SplitDelimitedValues().AsGuidList();
                            var familyAttributes = group.Attributes.Where( a =>
                                 familyAttributeGuidList.Contains( a.Value.Guid ) )
                                .Select( a => new
                                {
                                    Name = a.Value.Name,
                                    Value = a.Value.FieldType.Field.FormatValue( null, group.GetAttributeValue( a.Key ), a.Value.QualifierValues, a.Value.FieldType.Class == typeof( Rock.Field.Types.ImageFieldType ).FullName )
                                } )
                                .OrderBy( av => av.Name )
                                .ToList()
                                .Where( av => !String.IsNullOrWhiteSpace( av.Value ) );
                            if ( familyAttributes.Count() > 0 )
                            {
                                lFamilyHeader.Visible = true;
                                rptGroupAttributes.DataSource = familyAttributes;
                                rptGroupAttributes.DataBind();
                            }

                            rptGroupMembers.DataSource = group.Members.Where( gm =>
                                gm.PersonId != CurrentPerson.Id &&
                                gm.Person.IsDeceased == false )
                                .OrderBy( m => m.GroupRole.Order )
                                .ToList();
                            rptGroupMembers.DataBind();
                        }
                    }
                }

                if ( String.IsNullOrWhiteSpace( GetAttributeValue( "WorkflowLaunchPage" ) ) )
                {
                    lbRequestChanges.Visible = false;
                }
            }

            hfPersonId.Value = string.Empty;
            pnlEdit.Visible = false;
            pnlView.Visible = true;
        }