/// <summary> /// Binds the data. /// </summary> private void BindData() { ShowRole = GetAttributeValue("ShowRole").AsBoolean(); if (person != null && person.Id > 0) { if (ownerRoleGuid != Guid.Empty) { using (var rockContext = new RockContext()) { var memberService = new GroupMemberService(rockContext); var group = memberService.Queryable(true) .Where(m => m.PersonId == person.Id && m.GroupRole.Guid == ownerRoleGuid) .Select(m => m.Group) .FirstOrDefault(); if (group != null) { lGroupName.Text = group.Name.Pluralize(); lGroupTypeIcon.Text = string.Format("<i class='{0}'></i>", group.GroupType.IconCssClass); lGroupTypeIcon.Visible = !string.IsNullOrWhiteSpace(group.GroupType.IconCssClass); if (group.IsAuthorized(Authorization.VIEW, CurrentPerson)) { int?maxRelationshipsToDisplay = this.GetAttributeValue("MaxRelationshipsToDisplay").AsIntegerOrNull(); var roles = new List <int>(); if (canCheckInOnly) { foreach (var role in new GroupTypeRoleService(rockContext) .Queryable().AsNoTracking() .Where(r => r.GroupType.Guid.Equals(new Guid(Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS)))) { role.LoadAttributes(rockContext); if (role.Attributes.ContainsKey("CanCheckin")) { bool canCheckIn = false; if (bool.TryParse(role.GetAttributeValue("CanCheckin"), out canCheckIn) && canCheckIn) { roles.Add(role.Id); } } if (role.Attributes.ContainsKey("InverseRelationship")) { var inverseRoleGuid = role.GetAttributeValue("InverseRelationship").AsGuidOrNull(); if (inverseRoleGuid != null) { var groupTypeRole = new GroupTypeRoleService(rockContext) .Queryable().AsNoTracking() .FirstOrDefault(r => r.Guid.Equals(( Guid )inverseRoleGuid)); if (groupTypeRole != null) { groupTypeRole.LoadAttributes(rockContext); if (groupTypeRole.Attributes.ContainsKey("CanCheckin")) { bool canCheckIn = false; if (bool.TryParse(groupTypeRole.GetAttributeValue("CanCheckin"), out canCheckIn) && canCheckIn) { roles.Add(role.Id); } } } } } } } else { foreach (var role in new GroupTypeRoleService(rockContext) .Queryable().AsNoTracking() .Where(r => r.GroupType.Guid.Equals(new Guid(Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS)))) { roles.Add(role.Id); } } IQueryable <GroupMember> qryGroupMembers = new GroupMemberService(rockContext).GetByGroupId(group.Id, true) .Where(m => m.PersonId != person.Id) .Where(m => roles.Contains(m.GroupRoleId)) .OrderBy(m => m.Person.LastName) .ThenBy(m => m.Person.FirstName); if (maxRelationshipsToDisplay.HasValue) { qryGroupMembers = qryGroupMembers.Take(maxRelationshipsToDisplay.Value); } rGroupMembers.ItemDataBound += rptrMembers_ItemDataBound; rGroupMembers.DataSource = qryGroupMembers.ToList(); rGroupMembers.DataBind(); } else { lAccessWarning.Text = string.Format("<div class='alert alert-info'>You do not have security rights to view {0}.", group.Name.Pluralize()); } } } } } }