/// <summary> /// Gets the data. /// </summary> private int GetCount() { var personAliasEntityType = EntityTypeCache.Read( "Rock.Model.PersonAlias" ); if ( personAliasEntityType != null && CurrentPersonAlias != null ) { using ( var rockContext = new RockContext() ) { // PersonAlias query for joining the followed entity id to var personAliasQry = new PersonAliasService( rockContext ) .Queryable().AsNoTracking(); // Get all the people that the current person currently follows var followedPersonIds = new FollowingService( rockContext ) .Queryable().AsNoTracking() .Where( f => f.EntityTypeId == personAliasEntityType.Id && f.PersonAliasId == CurrentPersonAlias.Id ) .Join( personAliasQry, s => s.EntityId, p => p.Id, ( s, p ) => p.PersonId ) .Distinct(); // Get all the person suggestions for the current person that they are not already following return new FollowingSuggestedService( rockContext ) .Queryable( "SuggestionType" ).AsNoTracking() .Where( s => s.SuggestionType != null && s.EntityTypeId == personAliasEntityType.Id && s.PersonAliasId == CurrentPersonAlias.Id && s.Status != FollowingSuggestedStatus.Ignored ) .Join( personAliasQry, s => s.EntityId, p => p.Id, ( s, p ) => new { s, p } ) .Where( j => !followedPersonIds.Contains( j.p.PersonId ) ) .Count(); } } return 0; }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { if ( CurrentPersonAlias != null ) { var rockContext = new RockContext(); int personAliasEntityTypeId = EntityTypeCache.Read( "Rock.Model.PersonAlias" ).Id; var personAliasIds = new FollowingService( new RockContext() ).Queryable() .Where( f => f.EntityTypeId == personAliasEntityTypeId && f.PersonAliasId == CurrentPersonAlias.Id ) .Select( f => f.EntityId ) .Distinct() .ToList(); var qry = new PersonAliasService( rockContext ).Queryable() .Where( p => personAliasIds.Contains( p.Id ) ) .Select( p => p.Person ) .Distinct(); // Sort SortProperty sortProperty = gFollowings.SortProperty; if ( sortProperty == null ) { sortProperty = new SortProperty( new GridViewSortEventArgs( "LastName,NickName", SortDirection.Ascending ) ); } Guid homePhoneGuid = Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_HOME.AsGuid(); Guid cellPhoneGuid = Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_MOBILE.AsGuid(); Guid adultGuid = Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid(); Guid marriedGuid = Rock.SystemGuid.DefinedValue.PERSON_MARITAL_STATUS_MARRIED.AsGuid(); gFollowings.DataSource = qry.Sort( sortProperty ) .Select( p => new { p.Id, p.LastName, p.NickName, p.BirthDate, p.Email, HomePhone = p.PhoneNumbers .Where( n => n.NumberTypeValue.Guid.Equals(homePhoneGuid)) .Select( n => n.NumberFormatted) .FirstOrDefault(), CellPhone = p.PhoneNumbers .Where( n => n.NumberTypeValue.Guid.Equals( cellPhoneGuid ) ) .Select( n => n.NumberFormatted ) .FirstOrDefault(), SpouseName = p.Members .Where( m => p.MaritalStatusValue.Guid.Equals(marriedGuid) && m.GroupRole.Guid.Equals(adultGuid)) .SelectMany( m => m.Group.Members) .Where( m => m.PersonId != p.Id && m.GroupRole.Guid.Equals(adultGuid) && m.Person.MaritalStatusValue.Guid.Equals(marriedGuid) ) .Select( s => s.Person.NickName + " " + s.Person.LastName) .FirstOrDefault() } ).ToList(); gFollowings.DataBind(); } }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { var personAliasEntityType = EntityTypeCache.Read( "Rock.Model.PersonAlias" ); if ( personAliasEntityType != null && CurrentPersonAlias != null ) { var rockContext = new RockContext(); // PersonAlias query for joining the followed entity id to var personAliasQry = new PersonAliasService( rockContext ).Queryable(); // Get all the people that the current person currently follows var followedPersonIds = new FollowingService( rockContext ).Queryable() .Where( f => f.EntityTypeId == personAliasEntityType.Id && f.PersonAliasId == CurrentPersonAlias.Id ) .Join( personAliasQry, s => s.EntityId, p => p.Id, ( s, p ) => p.PersonId ) .Distinct(); // Get all the person suggestions for the current person that they are not already following var qry = new FollowingSuggestedService( rockContext ) .Queryable("SuggestionType") .Where( s => s.SuggestionType != null && s.EntityTypeId == personAliasEntityType.Id && s.PersonAliasId == CurrentPersonAlias.Id ) .Join( personAliasQry, s => s.EntityId, p => p.Id, ( s, p ) => new { s, p } ) .Where( j => !followedPersonIds.Contains( j.p.PersonId ) ) .Select( j => new { j.s.Id, j.s.LastPromotedDateTime, j.s.StatusChangedDateTime, j.s.SuggestionType.ReasonNote, j.s.Status, Person = j.p.Person, LastName = j.p.Person.LastName, NickName = j.p.Person.NickName } ); // Sort the result SortProperty sortProperty = gSuggestions.SortProperty; if ( sortProperty == null ) { sortProperty = new SortProperty( new GridViewSortEventArgs( "LastName,NickName", SortDirection.Ascending ) ); } // Bind grid to the query gSuggestions.DataSource = qry.Sort( sortProperty ) .Select( s => new { s.Id, s.LastPromotedDateTime, s.StatusChangedDateTime, s.ReasonNote, s.Status, StatusLabel = s.Status == FollowingSuggestedStatus.Ignored ? "<span class='label label-warning'>Ignored</span>" : "<span class='label label-success'>Suggested</span>", s.Person, s.LastName, s.NickName } ) .ToList(); gSuggestions.DataBind(); } }