Rock.UniversalSearch.IndexModels.BusinessIndex.LoadByModel C# (CSharp) Method

LoadByModel() public static method

Loads by model.
public static LoadByModel ( Person business ) : BusinessIndex
business Person The business.
return BusinessIndex
        public static BusinessIndex LoadByModel(Person business )
        {
            var businessIndex = new BusinessIndex();
            businessIndex.SourceIndexModel = "Rock.Model.Person";
            businessIndex.ModelConfiguration = "nofilters";

            businessIndex.ModelOrder = 6;

            businessIndex.Id = business.Id;
            businessIndex.Name = business.LastName;

            // do not currently index business attributes since they are shared with people
            //AddIndexableAttributes( businessIndex, person );

            var knownRelationshipGroupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS.AsGuid() );
            var knownRelationshipOwnerRoleId = knownRelationshipGroupType.Roles.Where( r => r.Guid == SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER.AsGuid() ).FirstOrDefault().Id;
            var knownRelationshipBusinessContactId = knownRelationshipGroupType.Roles.Where( r => r.Guid == SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_BUSINESS_CONTACT.AsGuid() ).FirstOrDefault().Id;

            RockContext rockContext = new RockContext();
            var contactGroup = new GroupMemberService( rockContext ).Queryable()
                                        .Where( m =>
                                             m.Group.GroupTypeId == knownRelationshipGroupType.Id
                                             && m.GroupRoleId == knownRelationshipOwnerRoleId
                                             && m.PersonId == business.Id)
                                        .FirstOrDefault();

            if ( contactGroup != null )
            {
                var contacts = new GroupMemberService( rockContext ).Queryable().AsNoTracking()
                                    .Where( m =>
                                         m.Group.GroupTypeId == knownRelationshipGroupType.Id
                                         && m.GroupId == contactGroup.GroupId
                                         && m.GroupRoleId == knownRelationshipBusinessContactId )
                                    .Select( m => m.Person.NickName + " " + m.Person.LastName ).ToList();

                if ( contacts != null )
                {
                    businessIndex.Contacts = string.Join( " ", contacts );
                }
            }

            return businessIndex;
        }