/// <summary> /// Loads by model. /// </summary> /// <param name="business">The business.</param> /// <returns></returns> 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; businessIndex.DocumentName = business.LastName; // get mailing address var address = business.GetMailingLocation(); if (address != null) { businessIndex.StreetAddress = address.Street1 + " " + address.Street2; businessIndex.City = address.City; businessIndex.State = address.State; businessIndex.PostalCode = address.PostalCode; businessIndex.Country = address.Country; } var knownRelationshipGroupType = GroupTypeCache.Get(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); }
/// <summary> /// Loads by model. /// </summary> /// <param name="business">The business.</param> /// <returns></returns> 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; businessIndex.DocumentName = business.LastName; // do not currently index business attributes since they are shared with people //AddIndexableAttributes( businessIndex, person ); var knownRelationshipGroupType = GroupTypeCache.Get(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); }
/// <summary> /// Loads by model. /// </summary> /// <param name="business">The business.</param> /// <returns></returns> 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; }