/// <summary>
        /// Searches the with details.
        /// </summary>
        /// <param name="reversed">if set to <c>true</c> [reversed].</param>
        /// <param name="sortedPersonQry">The sorted person qry.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        private List <PersonSearchResult> SearchWithDetails(IQueryable <Person> sortedPersonQry, bool showFullNameReversed)
        {
            var  rockContext      = this.Service.Context as Rock.Data.RockContext;
            var  phoneNumbersQry  = new PhoneNumberService(rockContext).Queryable();
            var  sortedPersonList = sortedPersonQry.Include(a => a.PhoneNumbers).AsNoTracking().ToList();
            Guid activeRecord     = new Guid(SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE);

            List <PersonSearchResult> searchResult = new List <PersonSearchResult>();

            foreach (var person in sortedPersonList)
            {
                PersonSearchResult personSearchResult = new PersonSearchResult();
                personSearchResult.Id   = person.Id;
                personSearchResult.Name = showFullNameReversed ? person.FullNameReversed : person.FullName;
                if (person.RecordStatusValueId.HasValue)
                {
                    var recordStatus = DefinedValueCache.Read(person.RecordStatusValueId.Value);
                    personSearchResult.RecordStatus = recordStatus.Value;
                    personSearchResult.IsActive     = recordStatus.Guid.Equals(activeRecord);
                }
                else
                {
                    personSearchResult.RecordStatus = string.Empty;
                    personSearchResult.IsActive     = false;
                }

                GetPersonSearchDetails(personSearchResult, person);

                searchResult.Add(personSearchResult);
            }

            return(searchResult);
        }
Example #2
0
        public PersonSearchResult GetPopupHtml(int personId)
        {
            var result = new PersonSearchResult();

            result.Id = personId;
            result.PickerItemDetailsHtml = "No Details Available";

            var html   = new StringBuilder();
            var person = new PersonService().Get(personId);

            if (person != null)
            {
                var appPath = System.Web.VirtualPathUtility.ToAbsolute("~");
                html.AppendFormat("<header>{0} <h3>{1}<small>{2}</small></h3></header>",
                                  Person.GetPhotoImageTag(person.PhotoId, person.Gender, 65, 65),
                                  person.FullName,
                                  person.ConnectionStatusValueId.HasValue ? person.ConnectionStatusValue.Name : string.Empty);

                var spouse = person.GetSpouse();
                if (spouse != null)
                {
                    html.AppendFormat("<strong>Spouse</strong> {0}",
                                      spouse.LastName == person.LastName ? spouse.FirstName : spouse.FullName);
                }

                int?age = person.Age;
                if (age.HasValue)
                {
                    html.AppendFormat("<br/><strong>Age</strong> {0}", age);
                }

                if (!string.IsNullOrWhiteSpace(person.Email))
                {
                    html.AppendFormat("<br/><strong>Email</strong> <a href='mailto:{0}'>{0}</a>", person.Email);
                }

                foreach (var phoneNumber in person.PhoneNumbers.Where(n => n.IsUnlisted == false).OrderBy(n => n.NumberTypeValue.Order))
                {
                    html.AppendFormat("<br/><strong>{0}</strong> {1}", phoneNumber.NumberTypeValue.Name, phoneNumber.NumberFormatted);
                }

                // TODO: Should also show area: <br /><strong>Area</strong> WestwingS

                result.PickerItemDetailsHtml = html.ToString();
            }

            return(result);
        }
        public string GetSearchDetails(int Id)
        {
            PersonSearchResult personSearchResult = new PersonSearchResult();
            var person = this.Get().Include(a => a.PhoneNumbers).Where(a => a.Id == Id).FirstOrDefault();

            if (person != null)
            {
                GetPersonSearchDetails(personSearchResult, person);
                string searchDetailsFormat = @"{0}<div class='contents'>{1}</div>";
                return(string.Format(searchDetailsFormat, personSearchResult.PickerItemDetailsImageHtml, personSearchResult.PickerItemDetailsPersonInfoHtml));
            }
            else
            {
                return(null);
            }
        }
Example #4
0
        public string GetSearchDetails(int Id)
        {
            PersonSearchResult personSearchResult = new PersonSearchResult();
            var person = this.Get().Include(a => a.PhoneNumbers).Where(a => a.Id == Id).FirstOrDefault();

            if (person != null)
            {
                GetPersonSearchDetails(personSearchResult, person);
                // Generate the HTML for the ConnectionStatus; "label-success" matches the default config of the
                // connection status badge on the Bio bar, but I think label-default works better here.
                string connectionStatusHtml = string.IsNullOrWhiteSpace(personSearchResult.ConnectionStatus) ? string.Empty : string.Format("<span class='label label-default pull-right'>{0}</span>", personSearchResult.ConnectionStatus);
                string searchDetailsFormat  = @"{0}{1}<div class='contents'>{2}</div>";
                return(string.Format(searchDetailsFormat, personSearchResult.PickerItemDetailsImageHtml, connectionStatusHtml, personSearchResult.PickerItemDetailsPersonInfoHtml));
            }
            else
            {
                return(null);
            }
        }
        public PersonSearchResult GetPopupHtml( int personId, bool emailAsLink )
        {
            var result = new PersonSearchResult();
            result.Id = personId;
            result.PickerItemDetailsHtml = "No Details Available";

            var html = new StringBuilder();

            // Create new service (need ProxyServiceEnabled)
            var rockContext = new Rock.Data.RockContext();
            var person = new PersonService( rockContext ).Queryable( "ConnectionStatusValue, PhoneNumbers" )
                .Where( p => p.Id == personId )
                .FirstOrDefault();

            if ( person != null )
            {
                Guid? recordTypeValueGuid = null;
                if ( person.RecordTypeValueId.HasValue )
                {
                    recordTypeValueGuid = DefinedValueCache.Read( person.RecordTypeValueId.Value ).Guid;
                }

                var appPath = System.Web.VirtualPathUtility.ToAbsolute( "~" );
                html.AppendFormat(
                    "<header>{0} <h3>{1}<small>{2}</small></h3></header>",
                    Person.GetPersonPhotoImageTag( person, 65, 65 ),
                    person.FullName,
                    person.ConnectionStatusValue != null ? person.ConnectionStatusValue.Value : string.Empty );

                html.Append( "<div class='body'>" );

                var spouse = person.GetSpouse( rockContext );
                if ( spouse != null )
                {
                    html.AppendFormat(
                        "<div><strong>Spouse</strong> {0}</div>",
                        spouse.LastName == person.LastName ? spouse.FirstName : spouse.FullName );
                }

                int? age = person.Age;
                if ( age.HasValue )
                {
                    html.AppendFormat( "<div><strong>Age</strong> {0}</div>" , age );
                }

                if ( !string.IsNullOrWhiteSpace( person.Email ) )
                {
                    if ( emailAsLink )
                    {
                        html.AppendFormat( "<div style='text-overflow: ellipsis; white-space: nowrap; overflow:hidden; width: 245px;'><strong>Email</strong> {0}</div>", person.GetEmailTag( VirtualPathUtility.ToAbsolute( "~/" ) ) );
                    }
                    else
                    {
                        html.AppendFormat( "<div style='text-overflow: ellipsis; white-space: nowrap; overflow:hidden; width: 245px;'><strong>Email</strong> {0}</div>", person.Email );
                    }
                }

                foreach ( var phoneNumber in person.PhoneNumbers.Where( n => n.IsUnlisted == false && n.NumberTypeValueId.HasValue ).OrderBy( n => n.NumberTypeValue.Order ) )
                {
                    html.AppendFormat( "<div><strong>{0}</strong> {1}</div>", phoneNumber.NumberTypeValue.Value, phoneNumber.ToString() );
                }

                html.Append( "</div>" );

                result.PickerItemDetailsHtml = html.ToString();
            }

            return result;
        }
        public PersonSearchResult GetPopupHtml(int personId, bool emailAsLink)
        {
            var result = new PersonSearchResult();

            result.Id = personId;
            result.PickerItemDetailsHtml = "No Details Available";

            var html = new StringBuilder();

            // Create new service (need ProxyServiceEnabled)
            var rockContext = new Rock.Data.RockContext();
            var person      = new PersonService(rockContext).Queryable("ConnectionStatusValue, PhoneNumbers")
                              .Where(p => p.Id == personId)
                              .FirstOrDefault();

            if (person != null)
            {
                Guid?recordTypeValueGuid = null;
                if (person.RecordTypeValueId.HasValue)
                {
                    recordTypeValueGuid = DefinedValueCache.Read(person.RecordTypeValueId.Value).Guid;
                }

                var appPath = System.Web.VirtualPathUtility.ToAbsolute("~");
                html.AppendFormat(
                    "<header>{0} <h3>{1}<small>{2}</small></h3></header>",
                    Person.GetPhotoImageTag(person.PhotoId, person.Age, person.Gender, recordTypeValueGuid, 65, 65),
                    person.FullName,
                    person.ConnectionStatusValue != null ? person.ConnectionStatusValue.Value : string.Empty);

                html.Append("<div class='body'>");

                var spouse = person.GetSpouse(rockContext);
                if (spouse != null)
                {
                    html.AppendFormat(
                        "<div><strong>Spouse</strong> {0}</div>",
                        spouse.LastName == person.LastName ? spouse.FirstName : spouse.FullName);
                }

                int?age = person.Age;
                if (age.HasValue)
                {
                    html.AppendFormat("<div><strong>Age</strong> {0}</div>", age);
                }

                if (!string.IsNullOrWhiteSpace(person.Email))
                {
                    if (emailAsLink)
                    {
                        html.AppendFormat("<div style='text-overflow: ellipsis; white-space: nowrap; overflow:hidden; width: 245px;'><strong>Email</strong> {0}</div>", person.GetEmailTag(VirtualPathUtility.ToAbsolute("~/")));
                    }
                    else
                    {
                        html.AppendFormat("<div style='text-overflow: ellipsis; white-space: nowrap; overflow:hidden; width: 245px;'><strong>Email</strong> {0}</div>", person.Email);
                    }
                }

                foreach (var phoneNumber in person.PhoneNumbers.Where(n => n.IsUnlisted == false && n.NumberTypeValueId.HasValue).OrderBy(n => n.NumberTypeValue.Order))
                {
                    html.AppendFormat("<div><strong>{0}</strong> {1}</div>", phoneNumber.NumberTypeValue.Value, phoneNumber.ToString());
                }

                html.Append("</div>");

                result.PickerItemDetailsHtml = html.ToString();
            }

            return(result);
        }
        /// <summary>
        /// Gets the person search details.
        /// </summary>
        /// <param name="personSearchResult">The person search result.</param>
        /// <param name="person">The person.</param>
        private void GetPersonSearchDetails(PersonSearchResult personSearchResult, Person person)
        {
            var rockContext = this.Service.Context as Rock.Data.RockContext;

            var    appPath          = System.Web.VirtualPathUtility.ToAbsolute("~");
            string itemDetailFormat = @"
<div class='picker-select-item-details clearfix' style='display: none;'>
	{0}
	<div class='contents'>
        {1}
	</div>
</div>
";

            var familyGroupType = GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid());
            int adultRoleId     = familyGroupType.Roles.First(a => a.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid()).Id;

            int groupTypeFamilyId = GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid()).Id;

            // figure out Family, Address, Spouse
            GroupMemberService groupMemberService = new GroupMemberService(rockContext);

            Guid?recordTypeValueGuid = null;

            if (person.RecordTypeValueId.HasValue)
            {
                recordTypeValueGuid = DefinedValueCache.Read(person.RecordTypeValueId.Value).Guid;
            }

            personSearchResult.ImageHtmlTag     = Person.GetPhotoImageTag(person.PhotoId, person.Age, person.Gender, recordTypeValueGuid, 50, 50);
            personSearchResult.Age              = person.Age.HasValue ? person.Age.Value : -1;
            personSearchResult.ConnectionStatus = person.ConnectionStatusValueId.HasValue ? DefinedValueCache.Read(person.ConnectionStatusValueId.Value).Value : string.Empty;
            personSearchResult.Gender           = person.Gender.ConvertToString();
            personSearchResult.Email            = person.Email;

            string imageHtml = string.Format(
                "<div class='person-image' style='background-image:url({0}&width=65);background-size:cover;background-position:50%'></div>",
                Person.GetPhotoUrl(person.PhotoId, person.Age, person.Gender, recordTypeValueGuid));

            string personInfoHtml = string.Empty;
            Guid   matchLocationGuid;
            bool   isBusiness;

            if (recordTypeValueGuid.HasValue && recordTypeValueGuid == Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_BUSINESS.AsGuid())
            {
                isBusiness        = true;
                matchLocationGuid = Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_WORK.AsGuid();
            }
            else
            {
                isBusiness        = false;
                matchLocationGuid = Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid();
            }

            var familyGroupMember = groupMemberService.Queryable()
                                    .Where(a => a.PersonId == person.Id)
                                    .Where(a => a.Group.GroupTypeId == groupTypeFamilyId)
                                    .Select(s => new
            {
                s.GroupRoleId,
                GroupLocation = s.Group.GroupLocations.Where(a => a.GroupLocationTypeValue.Guid == matchLocationGuid).Select(a => a.Location).FirstOrDefault()
            }).FirstOrDefault();

            int?personAge = person.Age;

            if (familyGroupMember != null)
            {
                if (isBusiness)
                {
                    personInfoHtml += "Business";
                }
                else
                {
                    personInfoHtml += familyGroupType.Roles.First(a => a.Id == familyGroupMember.GroupRoleId).Name;
                }

                if (personAge != null)
                {
                    personInfoHtml += " <em>(" + personAge.ToString() + " yrs old)</em>";
                }

                if (familyGroupMember.GroupRoleId == adultRoleId)
                {
                    var personService = this.Service as PersonService;
                    var spouse        = personService.GetSpouse(person, a => new
                    {
                        a.Person.NickName,
                        a.Person.LastName,
                        a.Person.SuffixValueId
                    });

                    if (spouse != null)
                    {
                        string spouseFullName = Person.FormatFullName(spouse.NickName, spouse.LastName, spouse.SuffixValueId);
                        personInfoHtml += "<p><strong>Spouse:</strong> " + spouseFullName + "</p>";
                        personSearchResult.SpouseName = spouseFullName;
                    }
                }
            }
            else
            {
                if (personAge != null)
                {
                    personInfoHtml += personAge.ToString() + " yrs old";
                }
            }

            if (familyGroupMember != null)
            {
                var location = familyGroupMember.GroupLocation;

                if (location != null)
                {
                    string addressHtml = "<h5>Address</h5>" + location.GetFullStreetAddress().ConvertCrLfToHtmlBr();
                    personSearchResult.Address = location.GetFullStreetAddress();
                    personInfoHtml            += addressHtml;
                }
            }

            // Generate the HTML for Email and PhoneNumbers
            if (!string.IsNullOrWhiteSpace(person.Email) || person.PhoneNumbers.Any())
            {
                string emailAndPhoneHtml = "<p class='margin-t-sm'>";
                emailAndPhoneHtml += person.Email;
                string phoneNumberList = string.Empty;
                foreach (var phoneNumber in person.PhoneNumbers)
                {
                    var phoneType = DefinedValueCache.Read(phoneNumber.NumberTypeValueId ?? 0);
                    phoneNumberList += string.Format(
                        "<br>{0} <small>{1}</small>",
                        phoneNumber.IsUnlisted ? "Unlisted" : phoneNumber.NumberFormatted,
                        phoneType != null ? phoneType.Value : string.Empty);
                }

                emailAndPhoneHtml += phoneNumberList + "<p>";

                personInfoHtml += emailAndPhoneHtml;
            }

            personSearchResult.PickerItemDetailsImageHtml      = imageHtml;
            personSearchResult.PickerItemDetailsPersonInfoHtml = personInfoHtml;
            personSearchResult.PickerItemDetailsHtml           = string.Format(itemDetailFormat, imageHtml, personInfoHtml);
        }
Example #8
0
        public PersonSearchResult GetPopupHtml(int personId)
        {
            var result = new PersonSearchResult();

            result.Id = personId;
            result.PickerItemDetailsHtml = "No Details Available";

            var html = new StringBuilder();

            // Create new service (need ProxyServiceEnabled)
            var rockContext = new Rock.Data.RockContext();
            var person      = new PersonService(rockContext).Queryable("ConnectionStatusValue, PhoneNumbers")
                              .Where(p => p.Id == personId)
                              .FirstOrDefault();

            if (person != null)
            {
                Guid?recordTypeValueGuid = null;
                if (person.RecordTypeValueId.HasValue)
                {
                    recordTypeValueGuid = DefinedValueCache.Read(person.RecordTypeValueId.Value).Guid;
                }

                var appPath = System.Web.VirtualPathUtility.ToAbsolute("~");
                html.AppendFormat(
                    "<header>{0} <h3>{1}<small>{2}</small></h3></header>",
                    Person.GetPhotoImageTag(person.PhotoId, person.Age, person.Gender, recordTypeValueGuid, 65, 65),
                    person.FullName,
                    person.ConnectionStatusValue != null ? person.ConnectionStatusValue.Value : string.Empty);

                var spouse = person.GetSpouse(rockContext);
                if (spouse != null)
                {
                    html.AppendFormat(
                        "<strong>Spouse</strong> {0}",
                        spouse.LastName == person.LastName ? spouse.FirstName : spouse.FullName);
                }

                int?age = person.Age;
                if (age.HasValue)
                {
                    html.AppendFormat("<br/><strong>Age</strong> {0}", age);
                }

                if (!string.IsNullOrWhiteSpace(person.Email))
                {
                    html.AppendFormat("<br/><strong>Email</strong> <a href='mailto:{0}'>{0}</a>", person.Email);
                }

                foreach (var phoneNumber in person.PhoneNumbers.Where(n => n.IsUnlisted == false).OrderBy(n => n.NumberTypeValue.Order))
                {
                    html.AppendFormat("<br/><strong>{0}</strong> {1}", phoneNumber.NumberTypeValue.Value, phoneNumber.ToString());
                }

                // TODO: Should also show area: <br /><strong>Area</strong> WestwingS

                result.PickerItemDetailsHtml = html.ToString();
            }

            return(result);
        }
        public PersonSearchResult GetPopupHtml( int personId )
        {
            var result = new PersonSearchResult();
            result.Id = personId;
            result.PickerItemDetailsHtml = "No Details Available";

            var html = new StringBuilder();
            var person = new PersonService().Get( personId );
            if ( person != null )
            {
                var appPath = System.Web.VirtualPathUtility.ToAbsolute( "~" );
                html.AppendFormat( "<header>{0} <h3>{1}<small>{2}</small></h3></header>",
                    Person.GetPhotoImageTag(person.PhotoId, person.Gender, 65,65),
                    person.FullName,
                    person.ConnectionStatusValueId.HasValue ? person.ConnectionStatusValue.Name : string.Empty );

                var spouse = person.GetSpouse();
                if (spouse != null)
                {
                    html.AppendFormat("<strong>Spouse</strong> {0}", 
                        spouse.LastName == person.LastName ? spouse.FirstName : spouse.FullName);
                }

                int? age = person.Age;
                if (age.HasValue)
                {
                    html.AppendFormat("<br/><strong>Age</strong> {0}", age); 
                }

                if (!string.IsNullOrWhiteSpace(person.Email))
                {
                    html.AppendFormat("<br/><strong>Email</strong> <a href='mailto:{0}'>{0}</a>", person.Email); 
                }

                foreach(var phoneNumber in person.PhoneNumbers.Where( n => n.IsUnlisted == false).OrderBy( n => n.NumberTypeValue.Order))
                {
                    html.AppendFormat("<br/><strong>{0}</strong> {1}", phoneNumber.NumberTypeValue.Name, phoneNumber.NumberFormatted);
                }

                // TODO: Should also show area: <br /><strong>Area</strong> WestwingS

                result.PickerItemDetailsHtml = html.ToString();
            }

            return result;
        }
        /// <summary>
        /// Searches the with details.
        /// </summary>
        /// <param name="reversed">if set to <c>true</c> [reversed].</param>
        /// <param name="sortedPersonQry">The sorted person qry.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        private List<PersonSearchResult> SearchWithDetails( IQueryable<Person> sortedPersonQry, bool showFullNameReversed )
        {
            var rockContext = this.Service.Context as Rock.Data.RockContext;
            var phoneNumbersQry = new PhoneNumberService( rockContext ).Queryable();
            var sortedPersonList = sortedPersonQry.Include( a => a.PhoneNumbers ).AsNoTracking().ToList();
            Guid activeRecord = new Guid( SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE );

            List<PersonSearchResult> searchResult = new List<PersonSearchResult>();
            foreach ( var person in sortedPersonList )
            {
                PersonSearchResult personSearchResult = new PersonSearchResult();
                personSearchResult.Id = person.Id;
                personSearchResult.Name = showFullNameReversed ? person.FullNameReversed : person.FullName;
                if ( person.RecordStatusValueId.HasValue )
                {
                    var recordStatus = DefinedValueCache.Read( person.RecordStatusValueId.Value );
                    personSearchResult.RecordStatus = recordStatus.Value;
                    personSearchResult.IsActive = recordStatus.Guid.Equals( activeRecord );
                }
                else
                {
                    personSearchResult.RecordStatus = string.Empty;
                    personSearchResult.IsActive = false;
                }

                GetPersonSearchDetails( personSearchResult, person );

                searchResult.Add( personSearchResult );
            }

            return searchResult;
        }
Example #11
0
        public IQueryable <PersonSearchResult> Search(string name, bool includeHtml)
        {
            int  count = 20;
            bool reversed;
            IOrderedQueryable <Person> sortedPersonQry = new PersonService().Queryable().QueryByName(name, out reversed);

            var           topQry           = sortedPersonQry.Take(count);
            List <Person> sortedPersonList = topQry.ToList();

            var    appPath          = System.Web.VirtualPathUtility.ToAbsolute("~");
            string itemDetailFormat = @"
<div class='picker-select-item-details clearfix' style='display: none;'>
	{0}
	<div class='contents'>
        {1}
	</div>
</div>
";

            Guid activeRecord = new Guid(SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE);

            // figure out Family, Address, Spouse
            GroupMemberService groupMemberService = new GroupMemberService();

            List <PersonSearchResult> searchResult = new List <PersonSearchResult>();

            foreach (var person in sortedPersonList)
            {
                PersonSearchResult personSearchResult = new PersonSearchResult();
                personSearchResult.Name             = reversed ? person.FullNameReversed : person.FullName;
                personSearchResult.ImageHtmlTag     = Person.GetPhotoImageTag(person.PhotoId, person.Gender, 50, 50);
                personSearchResult.Age              = person.Age.HasValue ? person.Age.Value : -1;
                personSearchResult.ConnectionStatus = person.ConnectionStatusValue != null ? person.ConnectionStatusValue.Name : string.Empty;
                personSearchResult.Gender           = person.Gender.ConvertToString();

                if (person.RecordStatusValue != null)
                {
                    personSearchResult.RecordStatus = person.RecordStatusValue.Name;
                    personSearchResult.IsActive     = person.RecordStatusValue.Guid.Equals(activeRecord);
                }
                else
                {
                    personSearchResult.RecordStatus = string.Empty;
                    personSearchResult.IsActive     = false;
                }

                personSearchResult.Id = person.Id;

                if (includeHtml)
                {
                    string imageHtml = null;

                    imageHtml = Person.GetPhotoImageTag(person.PhotoId, person.Gender, 65, 65);

                    string personInfo = string.Empty;

                    var groupMemberQry = groupMemberService.Queryable().Where(a => a.PersonId.Equals(person.Id));
                    List <GroupMember> personGroupMember = groupMemberQry.ToList();

                    Guid familyGuid = new Guid(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY);
                    Guid adultGuid  = new Guid(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT);

                    GroupMember familyGroupMember = personGroupMember.Where(a => a.Group.GroupType.Guid.Equals(familyGuid)).FirstOrDefault();
                    if (familyGroupMember != null)
                    {
                        personInfo += familyGroupMember.GroupRole.Name;
                        if (person.Age != null)
                        {
                            personInfo += " <em>(" + person.Age.ToString() + " yrs old)</em>";
                        }

                        // Figure out spouse (Implied by "the other GROUPROLE_FAMILY_MEMBER_ADULT that is of the opposite gender")
                        if (familyGroupMember.GroupRole.Guid.Equals(adultGuid))
                        {
                            person.GetSpouse();
                            GroupMember spouseMember = familyGroupMember.Group.Members.Where(a => !a.PersonId.Equals(person.Id) && a.GroupRole.Guid.Equals(adultGuid)).FirstOrDefault();
                            if (spouseMember != null)
                            {
                                if (!familyGroupMember.Person.Gender.Equals(spouseMember.Person.Gender))
                                {
                                    personInfo += "<p><strong>Spouse:</strong> " + spouseMember.Person.FullName + "</p>";
                                }
                            }
                        }
                    }
                    else
                    {
                        if (person.Age != null)
                        {
                            personInfo += person.Age.ToString() + " yrs old";
                        }
                    }

                    if (familyGroupMember != null)
                    {
                        var groupLocation = familyGroupMember.Group.GroupLocations.FirstOrDefault();
                        if (groupLocation != null)
                        {
                            var location = groupLocation.Location;
                            if (location != null)
                            {
                                string streetInfo;
                                if (!string.IsNullOrWhiteSpace(location.Street1))
                                {
                                    streetInfo = location.Street1 + " " + location.Street2;
                                }
                                else
                                {
                                    streetInfo = location.Street2;
                                }

                                string addressHtml = string.Format("<h5>Address</h5>{0} <br />{1}, {2}, {3}", streetInfo, location.City, location.State, location.Zip);
                                personInfo += addressHtml;
                            }
                        }
                    }

                    personSearchResult.PickerItemDetailsHtml = string.Format(itemDetailFormat, imageHtml, personInfo);
                }

                searchResult.Add(personSearchResult);
            }

            return(searchResult.AsQueryable());
        }
        /// <summary>
        /// Gets the person search details.
        /// </summary>
        /// <param name="personSearchResult">The person search result.</param>
        /// <param name="person">The person.</param>
        private void GetPersonSearchDetails(PersonSearchResult personSearchResult, Person person)
        {
            var rockContext = this.Service.Context as Rock.Data.RockContext;

            var    appPath          = System.Web.VirtualPathUtility.ToAbsolute("~");
            string itemDetailFormat = @"
<div class='picker-select-item-details clearfix' style='display: none;'>
	{0}
	<div class='contents'>
        {1}
	</div>
</div>
";

            var familyGroupType = GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid());
            int adultRoleId     = familyGroupType.Roles.First(a => a.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid()).Id;

            int groupTypeFamilyId = GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid()).Id;

            // figure out Family, Address, Spouse
            GroupMemberService groupMemberService = new GroupMemberService(rockContext);

            Guid?recordTypeValueGuid = null;

            if (person.RecordTypeValueId.HasValue)
            {
                recordTypeValueGuid = DefinedValueCache.Read(person.RecordTypeValueId.Value).Guid;
            }

            personSearchResult.ImageHtmlTag     = Person.GetPersonPhotoImageTag(person, 50, 50);
            personSearchResult.Age              = person.Age.HasValue ? person.Age.Value : -1;
            personSearchResult.ConnectionStatus = person.ConnectionStatusValueId.HasValue ? DefinedValueCache.Read(person.ConnectionStatusValueId.Value).Value : string.Empty;
            personSearchResult.Gender           = person.Gender.ConvertToString();
            personSearchResult.Email            = person.Email;

            string imageHtml = string.Format(
                "<div class='person-image' style='background-image:url({0}&width=65);background-size:cover;background-position:50%'></div>",
                Person.GetPersonPhotoUrl(person, 200, 200));

            string personInfoHtml = string.Empty;
            Guid   matchLocationGuid;
            bool   isBusiness;

            if (recordTypeValueGuid.HasValue && recordTypeValueGuid == Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_BUSINESS.AsGuid())
            {
                isBusiness        = true;
                matchLocationGuid = Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_WORK.AsGuid();
            }
            else
            {
                isBusiness        = false;
                matchLocationGuid = Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid();
            }

            var familyGroupMember = groupMemberService.Queryable()
                                    .Where(a => a.PersonId == person.Id)
                                    .Where(a => a.Group.GroupTypeId == groupTypeFamilyId)
                                    .OrderBy(a => a.GroupOrder ?? int.MaxValue)
                                    .Select(s => new
            {
                s.GroupRoleId,
                GroupLocation = s.Group.GroupLocations.Where(a => a.GroupLocationTypeValue.Guid == matchLocationGuid).Select(a => a.Location).FirstOrDefault()
            }).FirstOrDefault();

            int?personAge = person.Age;

            if (familyGroupMember != null)
            {
                if (isBusiness)
                {
                    personInfoHtml += "Business";
                }
                else
                {
                    personInfoHtml += "<div class='role'>" + familyGroupType.Roles.First(a => a.Id == familyGroupMember.GroupRoleId).Name + "</div>";
                }

                if (personAge != null)
                {
                    personInfoHtml += " <em class='age'>(" + person.FormatAge() + " old)</em>";
                }

                if (familyGroupMember.GroupRoleId == adultRoleId)
                {
                    var personService = this.Service as PersonService;
                    var spouse        = personService.GetSpouse(person, a => new
                    {
                        a.Person.NickName,
                        a.Person.LastName,
                        a.Person.SuffixValueId
                    });

                    if (spouse != null)
                    {
                        string spouseFullName = Person.FormatFullName(spouse.NickName, spouse.LastName, spouse.SuffixValueId);
                        personInfoHtml += "<p class='spouse'><strong>Spouse:</strong> " + spouseFullName + "</p>";
                        personSearchResult.SpouseName = spouseFullName;
                    }
                }
            }
            else
            {
                if (personAge != null)
                {
                    personInfoHtml += personAge.ToString() + " yrs old";
                }
            }

            if (familyGroupMember != null)
            {
                var location = familyGroupMember.GroupLocation;

                if (location != null)
                {
                    string addressHtml = "<div class='address'><h5>Address</h5>" + location.GetFullStreetAddress().ConvertCrLfToHtmlBr() + "</div>";
                    personSearchResult.Address = location.GetFullStreetAddress();
                    personInfoHtml            += addressHtml;
                }
            }

            // Generate the HTML for Email and PhoneNumbers
            if (!string.IsNullOrWhiteSpace(person.Email) || person.PhoneNumbers.Any())
            {
                string emailAndPhoneHtml = "<div class='margin-t-sm'>";
                emailAndPhoneHtml += "<span class='email'>" + person.Email + "</span>";
                string phoneNumberList = "<div class='phones'>";
                foreach (var phoneNumber in person.PhoneNumbers)
                {
                    var phoneType = DefinedValueCache.Read(phoneNumber.NumberTypeValueId ?? 0);
                    phoneNumberList += string.Format(
                        "<br>{0} <small>{1}</small>",
                        phoneNumber.IsUnlisted ? "Unlisted" : phoneNumber.NumberFormatted,
                        phoneType != null ? phoneType.Value : string.Empty);
                }

                emailAndPhoneHtml += phoneNumberList + "</div></div>";

                personInfoHtml += emailAndPhoneHtml;
            }

            // force the link to open a new scrollable,resizable browser window (and make it work in FF, Chrome and IE) http://stackoverflow.com/a/2315916/1755417
            personInfoHtml += $"<p class='margin-t-sm'><small><a class='cursor-pointer' onclick=\"javascript: window.open('/person/{person.Id}', '_blank', 'scrollbars=1,resizable=1,toolbar=1'); return false;\" data-toggle=\"tooltip\" title=\"View Profile\">View Profile</a></small></p>";

            personSearchResult.PickerItemDetailsImageHtml      = imageHtml;
            personSearchResult.PickerItemDetailsPersonInfoHtml = personInfoHtml;
            personSearchResult.PickerItemDetailsHtml           = string.Format(itemDetailFormat, imageHtml, personInfoHtml);
        }
        /// <summary>
        /// Gets the person search details.
        /// </summary>
        /// <param name="personSearchResult">The person search result.</param>
        /// <param name="person">The person.</param>
        private void GetPersonSearchDetails(PersonSearchResult personSearchResult, Person person)
        {
            var rockContext = this.Service.Context as Rock.Data.RockContext;

            var appPath = System.Web.VirtualPathUtility.ToAbsolute("~");

            var familyGroupType = GroupTypeCache.Get(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid());
            int adultRoleId     = familyGroupType.Roles.First(a => a.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid()).Id;

            int groupTypeFamilyId = GroupTypeCache.Get(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid()).Id;

            // figure out Family, Address, Spouse
            GroupMemberService groupMemberService = new GroupMemberService(rockContext);

            Guid?recordTypeValueGuid = null;

            if (person.RecordTypeValueId.HasValue)
            {
                recordTypeValueGuid = DefinedValueCache.Get(person.RecordTypeValueId.Value).Guid;
            }

            personSearchResult.ImageHtmlTag     = Person.GetPersonPhotoImageTag(person, 50, 50);
            personSearchResult.Age              = person.Age.HasValue ? person.Age.Value : -1;
            personSearchResult.ConnectionStatus = person.ConnectionStatusValueId.HasValue ? DefinedValueCache.Get(person.ConnectionStatusValueId.Value).Value : string.Empty;
            personSearchResult.Gender           = person.Gender.ConvertToString();
            personSearchResult.Email            = person.Email;

            string imageHtml = string.Format(
                "<div class='person-image' style='background-image:url({0}&width=65);'></div>",
                Person.GetPersonPhotoUrl(person, 200, 200));

            StringBuilder personInfoHtmlBuilder = new StringBuilder();
            int?          groupLocationTypeValueId;
            bool          isBusiness = person.IsBusiness();

            if (isBusiness)
            {
                groupLocationTypeValueId = DefinedValueCache.GetId(Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_WORK.AsGuid());
            }
            else
            {
                groupLocationTypeValueId = DefinedValueCache.GetId(Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid());
            }

            int?personAge = person.Age;

            if (isBusiness)
            {
                personInfoHtmlBuilder.Append("Business");
            }
            else if (person.AgeClassification != AgeClassification.Unknown)
            {
                personInfoHtmlBuilder.Append("<span class='role'>" + person.AgeClassification.ConvertToString() + "</span>");
            }

            if (personAge != null)
            {
                personInfoHtmlBuilder.Append(" <em class='age'>(" + person.FormatAge() + " old)</em>");
            }

            if (person.AgeClassification == AgeClassification.Adult)
            {
                var personService = this.Service as PersonService;
                var spouse        = personService.GetSpouse(person, a => new
                {
                    a.Person.NickName,
                    a.Person.LastName,
                    a.Person.SuffixValueId
                });

                if (spouse != null)
                {
                    string spouseFullName = Person.FormatFullName(spouse.NickName, spouse.LastName, spouse.SuffixValueId);
                    personInfoHtmlBuilder.Append("<p class='spouse'><strong>Spouse:</strong> " + spouseFullName + "</p>");
                    personSearchResult.SpouseName = spouseFullName;
                }
            }

            var primaryLocation = groupMemberService.Queryable()
                                  .Where(a => a.PersonId == person.Id)
                                  .Where(a => a.Group.GroupTypeId == groupTypeFamilyId)
                                  .OrderBy(a => a.GroupOrder ?? int.MaxValue)
                                  .Select(s => s.Group.GroupLocations.Where(a => a.GroupLocationTypeValueId == groupLocationTypeValueId).Select(a => a.Location).FirstOrDefault()
                                          ).AsNoTracking().FirstOrDefault();

            if (primaryLocation != null)
            {
                var    fullStreetAddress = primaryLocation.GetFullStreetAddress();
                string addressHtml       = $"<dl class='address'><dt>Address</dt><dd>{fullStreetAddress.ConvertCrLfToHtmlBr()}</dd></dl>";
                personSearchResult.Address = fullStreetAddress;
                personInfoHtmlBuilder.Append(addressHtml);
            }

            // Generate the HTML for Email and PhoneNumbers
            if (!string.IsNullOrWhiteSpace(person.Email) || person.PhoneNumbers.Any())
            {
                StringBuilder sbEmailAndPhoneHtml = new StringBuilder();
                sbEmailAndPhoneHtml.Append("<div class='margin-t-sm'>");
                sbEmailAndPhoneHtml.Append("<span class='email'>" + person.Email + "</span>");
                string phoneNumberList = "<ul class='phones list-unstyled'>";
                foreach (var phoneNumber in person.PhoneNumbers)
                {
                    var phoneType = DefinedValueCache.Get(phoneNumber.NumberTypeValueId ?? 0);
                    phoneNumberList += string.Format(
                        "<li x-ms-format-detection='none'>{0} <small>{1}</small></li>",
                        phoneNumber.IsUnlisted ? "Unlisted" : phoneNumber.NumberFormatted,
                        phoneType != null ? phoneType.Value : string.Empty);
                }

                sbEmailAndPhoneHtml.Append(phoneNumberList + "</ul></div>");

                personInfoHtmlBuilder.Append(sbEmailAndPhoneHtml.ToString());
            }

            // force the link to open a new scrollable, re-sizable browser window (and make it work in FF, Chrome and IE) http://stackoverflow.com/a/2315916/1755417
            personInfoHtmlBuilder.Append($"<p class='margin-t-sm'><small><a href='/person/{person.Id}' class='cursor-pointer' onclick=\"javascript: window.open('/person/{person.Id}', '_blank', 'scrollbars=1,resizable=1,toolbar=1'); return false;\" data-toggle=\"tooltip\" title=\"View Profile\" tabindex=\"-1\">View Profile</a></small></p>");

            personSearchResult.PickerItemDetailsImageHtml      = imageHtml;
            personSearchResult.PickerItemDetailsPersonInfoHtml = personInfoHtmlBuilder.ToString();
            string itemDetailHtml = $@"
<div class='picker-select-item-details js-picker-select-item-details clearfix' style='display: none;'>
	{imageHtml}
	<div class='contents'>
        {personSearchResult.PickerItemDetailsPersonInfoHtml}
	</div>
</div>
";

            personSearchResult.PickerItemDetailsHtml = itemDetailHtml;
        }
        public IQueryable<PersonSearchResult> Search( string name, bool includeHtml, bool includeBusinesses )
        {
            int count = 20;
            bool reversed;
            bool allowFirstNameOnly = false;

            var searchComponent = Rock.Search.SearchContainer.GetComponent( typeof( Rock.Search.Person.Name ).FullName );
            if ( searchComponent != null )
            {
                allowFirstNameOnly = searchComponent.GetAttributeValue( "FirstNameSearch" ).AsBoolean();
            }

            IOrderedQueryable<Person> sortedPersonQry = ( this.Service as PersonService )
                .GetByFullNameOrdered( name, true, includeBusinesses, allowFirstNameOnly, out reversed );

            var topQry = sortedPersonQry.Take( count );

            var sortedPersonList = topQry.AsNoTracking().ToList();

            var appPath = System.Web.VirtualPathUtility.ToAbsolute( "~" );
            string itemDetailFormat = @"
<div class='picker-select-item-details clearfix' style='display: none;'>
	{0}
	<div class='contents'>
        {1}
	</div>
</div>
";
            Guid activeRecord = new Guid( SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE );
            var familyGroupTypeRoles = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY ).Roles;
            int adultRoleId = familyGroupTypeRoles.First( a => a.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid() ).Id;

            int groupTypeFamilyId = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY ).Id;

            // figure out Family, Address, Spouse
            GroupMemberService groupMemberService = new GroupMemberService( this.Service.Context as Rock.Data.RockContext );

            List<PersonSearchResult> searchResult = new List<PersonSearchResult>();
            foreach ( var person in sortedPersonList )
            {
                PersonSearchResult personSearchResult = new PersonSearchResult();
                personSearchResult.Name = reversed ? person.FullNameReversed : person.FullName;

                Guid? recordTypeValueGuid = null;
                if ( person.RecordTypeValueId.HasValue )
                {
                    recordTypeValueGuid = DefinedValueCache.Read( person.RecordTypeValueId.Value ).Guid;
                }

                personSearchResult.ImageHtmlTag = Person.GetPhotoImageTag( person.PhotoId, person.Age, person.Gender, recordTypeValueGuid, 50, 50 );
                personSearchResult.Age = person.Age.HasValue ? person.Age.Value : -1;
                personSearchResult.ConnectionStatus = person.ConnectionStatusValueId.HasValue ? DefinedValueCache.Read( person.ConnectionStatusValueId.Value ).Value : string.Empty;
                personSearchResult.Gender = person.Gender.ConvertToString();
                personSearchResult.Email = person.Email;

                if ( person.RecordStatusValueId.HasValue )
                {
                    var recordStatus = DefinedValueCache.Read( person.RecordStatusValueId.Value );
                    personSearchResult.RecordStatus = recordStatus.Value;
                    personSearchResult.IsActive = recordStatus.Guid.Equals( activeRecord );
                }
                else
                {
                    personSearchResult.RecordStatus = string.Empty;
                    personSearchResult.IsActive = false;
                }

                personSearchResult.Id = person.Id;

                string imageHtml = string.Format(
                    "<div class='person-image' style='background-image:url({0}&width=65);background-size:cover;background-position:50%'></div>",
                    Person.GetPhotoUrl( person.PhotoId, person.Age, person.Gender, recordTypeValueGuid ) );

                string personInfo = string.Empty;
                Guid homeLocationGuid = Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid();

                var familyGroupMember = groupMemberService.Queryable()
                    .Where( a => a.PersonId == person.Id )
                    .Where( a => a.Group.GroupTypeId == groupTypeFamilyId )
                    .Select( s => new
                    {
                        s.GroupRoleId,
                        GroupLocation = s.Group.GroupLocations.Where( a => a.GroupLocationTypeValue.Guid == homeLocationGuid ).Select( a => a.Location ).FirstOrDefault()
                    } ).FirstOrDefault();

                int? personAge = person.Age;

                if ( familyGroupMember != null )
                {
                    if ( recordTypeValueGuid.HasValue && recordTypeValueGuid == Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_BUSINESS.AsGuid() )
                    {
                        personInfo += "Business";
                    }
                    else
                    {
                        personInfo += familyGroupTypeRoles.First( a => a.Id == familyGroupMember.GroupRoleId ).Name;
                    }
                    
                    if ( personAge != null )
                    {
                        personInfo += " <em>(" + personAge.ToString() + " yrs old)</em>";
                    }

                    if ( familyGroupMember.GroupRoleId == adultRoleId )
                    {
                        Person spouse = person.GetSpouse( this.Service.Context as Rock.Data.RockContext );
                        if ( spouse != null )
                        {
                            string spouseFullName = spouse.FullName;
                            personInfo += "<p><strong>Spouse:</strong> " + spouseFullName + "</p>";
                            personSearchResult.SpouseName = spouseFullName;
                        }
                    }
                }
                else
                {
                    if ( personAge != null )
                    {
                        personInfo += personAge.ToString() + " yrs old";
                    }
                }

                if ( familyGroupMember != null )
                {
                    var location = familyGroupMember.GroupLocation;

                    if ( location != null )
                    {
                        string addressHtml = "<h5>Address</h5>" + location.GetFullStreetAddress().ConvertCrLfToHtmlBr();
                        personSearchResult.Address = location.GetFullStreetAddress();
                        personInfo += addressHtml;
                    }

                    if ( includeHtml )
                    {
                        personSearchResult.PickerItemDetailsHtml = string.Format( itemDetailFormat, imageHtml, personInfo );
                    }
                }

                searchResult.Add( personSearchResult );
            }

            return searchResult.AsQueryable();
        }
 public string GetSearchDetails( int Id )
 {
     PersonSearchResult personSearchResult = new PersonSearchResult();
     var person = this.Get().Include( a => a.PhoneNumbers ).Where( a => a.Id == Id ).FirstOrDefault();
     if ( person != null )
     {
         GetPersonSearchDetails( personSearchResult, person );
         // Generate the HTML for the ConnectionStatus; "label-success" matches the default config of the
         // connection status badge on the Bio bar, but I think label-default works better here.
         string connectionStatusHtml = string.IsNullOrWhiteSpace( personSearchResult.ConnectionStatus ) ? string.Empty : string.Format( "<span class='label label-default pull-right'>{0}</span>", personSearchResult.ConnectionStatus );
         string searchDetailsFormat = @"{0}{1}<div class='contents'>{2}</div>";
         return string.Format( searchDetailsFormat, personSearchResult.PickerItemDetailsImageHtml, connectionStatusHtml, personSearchResult.PickerItemDetailsPersonInfoHtml );
     }
     else
     {
         return null;
     }
 }
        /// <summary>
        /// Gets the person search details.
        /// </summary>
        /// <param name="personSearchResult">The person search result.</param>
        /// <param name="person">The person.</param>
        private void GetPersonSearchDetails( PersonSearchResult personSearchResult, Person person )
        {
            var rockContext = this.Service.Context as Rock.Data.RockContext;

            var appPath = System.Web.VirtualPathUtility.ToAbsolute( "~" );
            string itemDetailFormat = @"
            <div class='picker-select-item-details clearfix' style='display: none;'>
            {0}
            <div class='contents'>
            {1}
            </div>
            </div>
            ";

            var familyGroupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid() );
            int adultRoleId = familyGroupType.Roles.First( a => a.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid() ).Id;

            int groupTypeFamilyId = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid() ).Id;

            // figure out Family, Address, Spouse
            GroupMemberService groupMemberService = new GroupMemberService( rockContext );

            Guid? recordTypeValueGuid = null;
            if ( person.RecordTypeValueId.HasValue )
            {
                recordTypeValueGuid = DefinedValueCache.Read( person.RecordTypeValueId.Value ).Guid;
            }

            personSearchResult.ImageHtmlTag = Person.GetPersonPhotoImageTag( person, 50, 50 );
            personSearchResult.Age = person.Age.HasValue ? person.Age.Value : -1;
            personSearchResult.ConnectionStatus = person.ConnectionStatusValueId.HasValue ? DefinedValueCache.Read( person.ConnectionStatusValueId.Value ).Value : string.Empty;
            personSearchResult.Gender = person.Gender.ConvertToString();
            personSearchResult.Email = person.Email;

            string imageHtml = string.Format(
                "<div class='person-image' style='background-image:url({0}&width=65);background-size:cover;background-position:50%'></div>",
                Person.GetPersonPhotoUrl( person, 200, 200 ) );

            string personInfoHtml = string.Empty;
            Guid matchLocationGuid;
            bool isBusiness;
            if ( recordTypeValueGuid.HasValue && recordTypeValueGuid == Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_BUSINESS.AsGuid() )
            {
                isBusiness = true;
                matchLocationGuid = Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_WORK.AsGuid();
            }
            else
            {
                isBusiness = false;
                matchLocationGuid = Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid();
            }

            var familyGroupMember = groupMemberService.Queryable()
                .Where( a => a.PersonId == person.Id )
                .Where( a => a.Group.GroupTypeId == groupTypeFamilyId )
                .Select( s => new
                {
                    s.GroupRoleId,
                    GroupLocation = s.Group.GroupLocations.Where( a => a.GroupLocationTypeValue.Guid == matchLocationGuid ).Select( a => a.Location ).FirstOrDefault()
                } ).FirstOrDefault();

            int? personAge = person.Age;

            if ( familyGroupMember != null )
            {
                if ( isBusiness )
                {
                    personInfoHtml += "Business";
                }
                else
                {
                    personInfoHtml += familyGroupType.Roles.First( a => a.Id == familyGroupMember.GroupRoleId ).Name;
                }

                if ( personAge != null )
                {
                    personInfoHtml += " <em>(" + personAge.ToString() + " yrs old)</em>";
                }

                if ( familyGroupMember.GroupRoleId == adultRoleId )
                {
                    var personService = this.Service as PersonService;
                    var spouse = personService.GetSpouse( person, a => new
                    {
                        a.Person.NickName,
                        a.Person.LastName,
                        a.Person.SuffixValueId
                    } );

                    if ( spouse != null )
                    {
                        string spouseFullName = Person.FormatFullName( spouse.NickName, spouse.LastName, spouse.SuffixValueId );
                        personInfoHtml += "<p><strong>Spouse:</strong> " + spouseFullName + "</p>";
                        personSearchResult.SpouseName = spouseFullName;
                    }
                }
            }
            else
            {
                if ( personAge != null )
                {
                    personInfoHtml += personAge.ToString() + " yrs old";
                }
            }

            if ( familyGroupMember != null )
            {
                var location = familyGroupMember.GroupLocation;

                if ( location != null )
                {
                    string addressHtml = "<h5>Address</h5>" + location.GetFullStreetAddress().ConvertCrLfToHtmlBr();
                    personSearchResult.Address = location.GetFullStreetAddress();
                    personInfoHtml += addressHtml;
                }
            }

            // Generate the HTML for Email and PhoneNumbers
            if ( !string.IsNullOrWhiteSpace( person.Email ) || person.PhoneNumbers.Any() )
            {
                string emailAndPhoneHtml = "<p class='margin-t-sm'>";
                emailAndPhoneHtml += person.Email;
                string phoneNumberList = string.Empty;
                foreach ( var phoneNumber in person.PhoneNumbers )
                {
                    var phoneType = DefinedValueCache.Read( phoneNumber.NumberTypeValueId ?? 0 );
                    phoneNumberList += string.Format(
                        "<br>{0} <small>{1}</small>",
                        phoneNumber.IsUnlisted ? "Unlisted" : phoneNumber.NumberFormatted,
                        phoneType != null ? phoneType.Value : string.Empty );
                }

                emailAndPhoneHtml += phoneNumberList + "<p>";

                personInfoHtml += emailAndPhoneHtml;
            }

            personSearchResult.PickerItemDetailsImageHtml = imageHtml;
            personSearchResult.PickerItemDetailsPersonInfoHtml = personInfoHtml;
            personSearchResult.PickerItemDetailsHtml = string.Format( itemDetailFormat, imageHtml, personInfoHtml );
        }
Example #17
0
        public PersonSearchResult GetPopupHtml( int personId )
        {
            var result = new PersonSearchResult();
            result.Id = personId;
            result.PickerItemDetailsHtml = "No Details Available";

            var html = new StringBuilder();

            // Create new service (need ProxyServiceEnabled)
            var rockContext = new Rock.Data.RockContext();
            var person = new PersonService( rockContext ).Queryable( "ConnectionStatusValue, PhoneNumbers" )
                .Where( p => p.Id == personId )
                .FirstOrDefault();

            if ( person != null )
            {
                Guid? recordTypeValueGuid = null;
                if ( person.RecordTypeValueId.HasValue )
                {
                    recordTypeValueGuid = DefinedValueCache.Read( person.RecordTypeValueId.Value ).Guid;
                }

                var appPath = System.Web.VirtualPathUtility.ToAbsolute( "~" );
                html.AppendFormat(
                    "<header>{0} <h3>{1}<small>{2}</small></h3></header>",
                    Person.GetPhotoImageTag( person.PhotoId, person.Age, person.Gender, recordTypeValueGuid, 65, 65 ),
                    person.FullName,
                    person.ConnectionStatusValue != null ? person.ConnectionStatusValue.Value : string.Empty );

                var spouse = person.GetSpouse( rockContext );
                if ( spouse != null )
                {
                    html.AppendFormat(
                        "<strong>Spouse</strong> {0}",
                        spouse.LastName == person.LastName ? spouse.FirstName : spouse.FullName );
                }

                int? age = person.Age;
                if ( age.HasValue )
                {
                    html.AppendFormat( "<br/><strong>Age</strong> {0}", age );
                }

                if ( !string.IsNullOrWhiteSpace( person.Email ) )
                {
                    html.AppendFormat( "<br/><strong>Email</strong> <a href='mailto:{0}'>{0}</a>", person.Email );
                }

                foreach ( var phoneNumber in person.PhoneNumbers.Where( n => n.IsUnlisted == false ).OrderBy( n => n.NumberTypeValue.Order ) )
                {
                    html.AppendFormat( "<br/><strong>{0}</strong> {1}", phoneNumber.NumberTypeValue.Value, phoneNumber.ToString() );
                }

                // TODO: Should also show area: <br /><strong>Area</strong> WestwingS

                result.PickerItemDetailsHtml = html.ToString();
            }

            return result;
        }
        public IQueryable<PersonSearchResult> Search( string name, bool includeHtml )
        {
            int count = 20;
            bool reversed;
            bool allowFirstNameOnly = false;

            var searchComponent = Rock.Search.SearchContainer.GetComponent( typeof( Rock.Search.Person.Name ) );
            if ( searchComponent != null )
            {
                allowFirstNameOnly = searchComponent.GetAttributeValue( "FirstNameSearch" ).AsBoolean();
            }

            var rockContext = new Rock.Data.RockContext();
            IOrderedQueryable<Person> sortedPersonQry = new PersonService( rockContext )
                .GetByFullNameOrdered( name, true, false, allowFirstNameOnly, out reversed );

            var topQry = sortedPersonQry.Take( count );
            List<Person> sortedPersonList = topQry.ToList();

            var appPath = System.Web.VirtualPathUtility.ToAbsolute( "~" );
            string itemDetailFormat = @"
<div class='picker-select-item-details clearfix' style='display: none;'>
	{0}
	<div class='contents'>
        {1}
	</div>
</div>
";
            Guid activeRecord = new Guid( SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE );

            // figure out Family, Address, Spouse
            GroupMemberService groupMemberService = new GroupMemberService( rockContext );

            List<PersonSearchResult> searchResult = new List<PersonSearchResult>();
            foreach ( var person in sortedPersonList )
            {
                PersonSearchResult personSearchResult = new PersonSearchResult();
                personSearchResult.Name = reversed ? person.FullNameReversed : person.FullName;
                personSearchResult.ImageHtmlTag = Person.GetPhotoImageTag( person.PhotoId, person.Gender, 50, 50 );
                personSearchResult.Age = person.Age.HasValue ? person.Age.Value : -1;
                personSearchResult.ConnectionStatus = person.ConnectionStatusValueId.HasValue ? DefinedValueCache.Read( person.ConnectionStatusValueId.Value ).Name : string.Empty;
                personSearchResult.Gender = person.Gender.ConvertToString();
                personSearchResult.Email = person.Email;

                if ( person.RecordStatusValueId.HasValue )
                {
                    var recordStatus = DefinedValueCache.Read( person.RecordStatusValueId.Value );
                    personSearchResult.RecordStatus = recordStatus.Name;
                    personSearchResult.IsActive = recordStatus.Guid.Equals( activeRecord );
                }
                else
                {
                    personSearchResult.RecordStatus = string.Empty;
                    personSearchResult.IsActive = false;
                }

                personSearchResult.Id = person.Id;

                string imageHtml = string.Format(
                    "<div class='person-image' style='background-image:url({0}&width=65);background-size:cover;background-position:50%'></div>",
                    Person.GetPhotoUrl( person.PhotoId, person.Gender ) );

                string personInfo = string.Empty;

                Guid adultGuid = new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT );

                Guid familyGuid = new Guid( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY );
                var familyGroupMember = groupMemberService.Queryable()
                    .Where( a => a.PersonId == person.Id )
                    .Where( a => a.Group.GroupType.Guid.Equals( familyGuid ) )
                    .Select( s => new
                    {
                        s.GroupRole,
                        GroupLocation = s.Group.GroupLocations.Select( a => a.Location ).FirstOrDefault()
                    } ).FirstOrDefault();

                if ( familyGroupMember != null )
                {
                    personInfo += familyGroupMember.GroupRole.Name;
                    if ( person.Age != null )
                    {
                        personInfo += " <em>(" + person.Age.ToString() + " yrs old)</em>";
                    }

                    if ( familyGroupMember.GroupRole.Guid.Equals( adultGuid ) )
                    {
                        var spouse = person.GetSpouse();
                        if ( spouse != null )
                        {
                            personInfo += "<p><strong>Spouse:</strong> " + spouse.FullName + "</p>";
                            personSearchResult.SpouseName = spouse.FullName;
                        }
                    }
                }
                else
                {
                    if ( person.Age != null )
                    {
                        personInfo += person.Age.ToString() + " yrs old";
                    }
                }

                if ( familyGroupMember != null )
                {
                    var location = familyGroupMember.GroupLocation;

                    if ( location != null )
                    {
                        string streetInfo;
                        if ( !string.IsNullOrWhiteSpace( location.Street1 ) )
                        {
                            streetInfo = location.Street1 + " " + location.Street2;
                        }
                        else
                        {
                            streetInfo = location.Street2;
                        }

                        string addressHtml = string.Format( "<h5>Address</h5>{0} <br />{1}, {2}, {3}", streetInfo, location.City, location.State, location.Zip );
                        personSearchResult.Address = location.ToString();
                        personInfo += addressHtml;
                    }

                    if ( includeHtml )
                    {
                        personSearchResult.PickerItemDetailsHtml = string.Format( itemDetailFormat, imageHtml, personInfo );
                    }
                }

                searchResult.Add( personSearchResult );
            }

            return searchResult.AsQueryable();
        }
Example #19
0
 public string GetSearchDetails( int Id )
 {
     PersonSearchResult personSearchResult = new PersonSearchResult();
     var person = this.Get().Include( a => a.PhoneNumbers ).Where( a => a.Id == Id ).FirstOrDefault();
     if ( person != null )
     {
         GetPersonSearchDetails( personSearchResult, person );
         string searchDetailsFormat = @"{0}<div class='contents'>{1}</div>";
         return string.Format( searchDetailsFormat, personSearchResult.PickerItemDetailsImageHtml, personSearchResult.PickerItemDetailsPersonInfoHtml );
     }
     else
     {
         return null;
     }
 }
Example #20
0
        public IQueryable<PersonSearchResult> Search( string name, bool includeHtml)
        {
            int count = 20;
            bool reversed;
            IOrderedQueryable<Person> sortedPersonQry = new PersonService().Queryable().QueryByName( name, out reversed );

            var topQry = sortedPersonQry.Take( count );
            List<Person> sortedPersonList = topQry.ToList();

            var appPath = System.Web.VirtualPathUtility.ToAbsolute( "~" );
            string itemDetailFormat = @"
<div class='picker-select-item-details clearfix' style='display: none;'>
	{0}
	<div class='contents'>
        {1}
	</div>
</div>
";

            Guid activeRecord = new Guid( SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE );
 
            // figure out Family, Address, Spouse
            GroupMemberService groupMemberService = new GroupMemberService();

            List<PersonSearchResult> searchResult = new List<PersonSearchResult>();
            foreach ( var person in sortedPersonList)
            {
                PersonSearchResult personSearchResult = new PersonSearchResult();
                personSearchResult.Name = reversed ? person.FullNameReversed : person.FullName;
                personSearchResult.ImageHtmlTag = Person.GetPhotoImageTag( person.PhotoId, person.Gender, 50, 50 );
                personSearchResult.Age = person.Age.HasValue ? person.Age.Value : -1;
                personSearchResult.ConnectionStatus = person.ConnectionStatusValue != null ? person.ConnectionStatusValue.Name : string.Empty;
                personSearchResult.Gender = person.Gender.ConvertToString();

                if ( person.RecordStatusValue != null )
                {
                    personSearchResult.RecordStatus = person.RecordStatusValue.Name;
                    personSearchResult.IsActive = person.RecordStatusValue.Guid.Equals( activeRecord );
                }
                else
                {
                    personSearchResult.RecordStatus = string.Empty;
                    personSearchResult.IsActive = false;
                }

                personSearchResult.Id = person.Id;

                if ( includeHtml )
                {
                    string imageHtml = null;

                    imageHtml = Person.GetPhotoImageTag(person.PhotoId, person.Gender, 65, 65);

                    string personInfo = string.Empty;

                    var groupMemberQry = groupMemberService.Queryable().Where( a => a.PersonId.Equals( person.Id ) );
                    List<GroupMember> personGroupMember = groupMemberQry.ToList();

                    Guid familyGuid = new Guid( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY );
                    Guid adultGuid = new Guid( Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT );

                    GroupMember familyGroupMember = personGroupMember.Where( a => a.Group.GroupType.Guid.Equals( familyGuid ) ).FirstOrDefault();
                    if ( familyGroupMember != null )
                    {
                        personInfo += familyGroupMember.GroupRole.Name;
                        if ( person.Age != null )
                        {
                            personInfo += " <em>(" + person.Age.ToString() + " yrs old)</em>";
                        }

                        // Figure out spouse (Implied by "the other GROUPROLE_FAMILY_MEMBER_ADULT that is of the opposite gender")
                        if ( familyGroupMember.GroupRole.Guid.Equals( adultGuid ) )
                        {
                            person.GetSpouse();
                            GroupMember spouseMember = familyGroupMember.Group.Members.Where( a => !a.PersonId.Equals( person.Id ) && a.GroupRole.Guid.Equals( adultGuid ) ).FirstOrDefault();
                            if ( spouseMember != null )
                            {
                                if ( !familyGroupMember.Person.Gender.Equals( spouseMember.Person.Gender ) )
                                {
                                    personInfo += "<p><strong>Spouse:</strong> " + spouseMember.Person.FullName + "</p>";
                                }
                            }
                        }
                    }
                    else
                    {
                        if ( person.Age != null )
                        {
                            personInfo += person.Age.ToString() + " yrs old";
                        }
                    }

                    if ( familyGroupMember != null )
                    {
                        var groupLocation = familyGroupMember.Group.GroupLocations.FirstOrDefault();
                        if ( groupLocation != null )
                        {
                            var location = groupLocation.Location;
                            if ( location != null )
                            {
                                string streetInfo;
                                if ( !string.IsNullOrWhiteSpace( location.Street1 ) )
                                {
                                    streetInfo = location.Street1 + " " + location.Street2;
                                }
                                else
                                {
                                    streetInfo = location.Street2;
                                }

                                string addressHtml = string.Format( "<h5>Address</h5>{0} <br />{1}, {2}, {3}", streetInfo, location.City, location.State, location.Zip );
                                personInfo += addressHtml;
                            }
                        }
                    }

                    personSearchResult.PickerItemDetailsHtml = string.Format( itemDetailFormat, imageHtml, personInfo );
                }

                searchResult.Add( personSearchResult );
            }
            
            return searchResult.AsQueryable();
        }
Example #21
0
        public IQueryable <PersonSearchResult> Search(string name, bool includeHtml, bool includeBusinesses)
        {
            int  count = 20;
            bool reversed;
            bool allowFirstNameOnly = false;

            var searchComponent = Rock.Search.SearchContainer.GetComponent(typeof(Rock.Search.Person.Name).FullName);

            if (searchComponent != null)
            {
                allowFirstNameOnly = searchComponent.GetAttributeValue("FirstNameSearch").AsBoolean();
            }

            IOrderedQueryable <Person> sortedPersonQry = (this.Service as PersonService)
                                                         .GetByFullNameOrdered(name, true, includeBusinesses, allowFirstNameOnly, out reversed);

            var topQry = sortedPersonQry.Take(count);

            var sortedPersonList = topQry.AsNoTracking().ToList();

            var    appPath              = System.Web.VirtualPathUtility.ToAbsolute("~");
            string itemDetailFormat     = @"
<div class='picker-select-item-details clearfix' style='display: none;'>
	{0}
	<div class='contents'>
        {1}
	</div>
</div>
";
            Guid   activeRecord         = new Guid(SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE);
            var    familyGroupTypeRoles = GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY).Roles;
            int    adultRoleId          = familyGroupTypeRoles.First(a => a.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid()).Id;

            int groupTypeFamilyId = GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY).Id;

            // figure out Family, Address, Spouse
            GroupMemberService groupMemberService = new GroupMemberService(this.Service.Context as Rock.Data.RockContext);

            List <PersonSearchResult> searchResult = new List <PersonSearchResult>();

            foreach (var person in sortedPersonList)
            {
                PersonSearchResult personSearchResult = new PersonSearchResult();
                personSearchResult.Name = reversed ? person.FullNameReversed : person.FullName;

                Guid?recordTypeValueGuid = null;
                if (person.RecordTypeValueId.HasValue)
                {
                    recordTypeValueGuid = DefinedValueCache.Read(person.RecordTypeValueId.Value).Guid;
                }

                personSearchResult.ImageHtmlTag     = Person.GetPhotoImageTag(person.PhotoId, person.Age, person.Gender, recordTypeValueGuid, 50, 50);
                personSearchResult.Age              = person.Age.HasValue ? person.Age.Value : -1;
                personSearchResult.ConnectionStatus = person.ConnectionStatusValueId.HasValue ? DefinedValueCache.Read(person.ConnectionStatusValueId.Value).Value : string.Empty;
                personSearchResult.Gender           = person.Gender.ConvertToString();
                personSearchResult.Email            = person.Email;

                if (person.RecordStatusValueId.HasValue)
                {
                    var recordStatus = DefinedValueCache.Read(person.RecordStatusValueId.Value);
                    personSearchResult.RecordStatus = recordStatus.Value;
                    personSearchResult.IsActive     = recordStatus.Guid.Equals(activeRecord);
                }
                else
                {
                    personSearchResult.RecordStatus = string.Empty;
                    personSearchResult.IsActive     = false;
                }

                personSearchResult.Id = person.Id;

                string imageHtml = string.Format(
                    "<div class='person-image' style='background-image:url({0}&width=65);background-size:cover;background-position:50%'></div>",
                    Person.GetPhotoUrl(person.PhotoId, person.Age, person.Gender, recordTypeValueGuid));

                string personInfo       = string.Empty;
                Guid   homeLocationGuid = Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid();

                var familyGroupMember = groupMemberService.Queryable()
                                        .Where(a => a.PersonId == person.Id)
                                        .Where(a => a.Group.GroupTypeId == groupTypeFamilyId)
                                        .Select(s => new
                {
                    s.GroupRoleId,
                    GroupLocation = s.Group.GroupLocations.Where(a => a.GroupLocationTypeValue.Guid == homeLocationGuid).Select(a => a.Location).FirstOrDefault()
                }).FirstOrDefault();

                int?personAge = person.Age;

                if (familyGroupMember != null)
                {
                    if (recordTypeValueGuid.HasValue && recordTypeValueGuid == Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_BUSINESS.AsGuid())
                    {
                        personInfo += "Business";
                    }
                    else
                    {
                        personInfo += familyGroupTypeRoles.First(a => a.Id == familyGroupMember.GroupRoleId).Name;
                    }

                    if (personAge != null)
                    {
                        personInfo += " <em>(" + personAge.ToString() + " yrs old)</em>";
                    }

                    if (familyGroupMember.GroupRoleId == adultRoleId)
                    {
                        Person spouse = person.GetSpouse(this.Service.Context as Rock.Data.RockContext);
                        if (spouse != null)
                        {
                            string spouseFullName = spouse.FullName;
                            personInfo += "<p><strong>Spouse:</strong> " + spouseFullName + "</p>";
                            personSearchResult.SpouseName = spouseFullName;
                        }
                    }
                }
                else
                {
                    if (personAge != null)
                    {
                        personInfo += personAge.ToString() + " yrs old";
                    }
                }

                if (familyGroupMember != null)
                {
                    var location = familyGroupMember.GroupLocation;

                    if (location != null)
                    {
                        string addressHtml = "<h5>Address</h5>" + location.GetFullStreetAddress().ConvertCrLfToHtmlBr();
                        personSearchResult.Address = location.GetFullStreetAddress();
                        personInfo += addressHtml;
                    }

                    if (includeHtml)
                    {
                        personSearchResult.PickerItemDetailsHtml = string.Format(itemDetailFormat, imageHtml, personInfo);
                    }
                }

                searchResult.Add(personSearchResult);
            }

            return(searchResult.AsQueryable());
        }