/// <summary> /// Binds the grid. /// </summary> public void BindGrid() { int targetId = int.Parse( PageParameter( "targetId" ) ); int viewerId = int.Parse( PageParameter( "viewerId" ) ); bool viewedBy = Convert.ToBoolean( PageParameter( "viewedBy" ) ); var personViewedService = new PersonViewedService( new RockContext() ); var personViewedList = personViewedService.Queryable() .Where( p => p.ViewerPersonAlias != null && p.ViewerPersonAlias.PersonId == viewerId && p.TargetPersonAlias != null && p.TargetPersonAlias.PersonId == targetId ) .Select( p => new { Id = p.TargetPersonAlias.PersonId, Source = p.Source, TargetPerson = p.TargetPersonAlias.Person, ViewerPerson = p.ViewerPersonAlias.Person, ViewDateTime = p.ViewDateTime, IpAddress = p.IpAddress } ).ToList(); if ( viewedBy ) { gridTitle.InnerText = string.Format( "{0} Viewed By {1}", personViewedList.Select( p => p.TargetPerson.FullName ).FirstOrDefault(), personViewedList.Select( p => p.ViewerPerson.FullName ).FirstOrDefault() ); } else { gridTitle.InnerText = string.Format( "{0} Viewed {1}", personViewedList.Select( p => p.ViewerPerson.FullName ).FirstOrDefault(), personViewedList.Select( p => p.TargetPerson.FullName ).FirstOrDefault() ); } SortProperty sortProperty = gViewDetails.SortProperty; if ( sortProperty != null ) { personViewedList = personViewedList.AsQueryable().Sort( sortProperty ).ToList(); } else { personViewedList = personViewedList.OrderByDescending( p => p.ViewDateTime ).ToList(); } gViewDetails.EntityTypeId = EntityTypeCache.Read<PersonViewed>().Id; gViewDetails.DataSource = personViewedList; gViewDetails.DataBind(); }
/// <summary> /// Binds the grid. /// </summary> protected void BindGrid() { var showProfilesViewed = GetAttributeValue( "SeeProfilesViewed" ).AsBoolean(); var rockContext = new RockContext(); var personViewedService = new PersonViewedService( rockContext ); var personService = new PersonService( rockContext ); if ( showProfilesViewed ) { // This grid should show the profiles viewed by this person. pnlViewed.Visible = true; pnlViewedBy.Visible = false; if ( personId.HasValue ) { var viewedList = personViewedService.Queryable() .Where( p => p.ViewerPersonAlias != null && p.ViewerPersonAlias.PersonId == personId ) .GroupBy( p => p.TargetPersonAlias.PersonId ) .Select( p => new { TargetPersonId = p.Key, FirstViewed = p.Min( g => g.ViewDateTime ), LastViewed = p.Max( g => g.ViewDateTime ), ViewedCount = p.Count() } ); var pQry = personService.Queryable(); var qry = viewedList .Join( pQry, v => v.TargetPersonId, p => p.Id, ( v, p ) => new { p.Id, FullName = p.NickName + " " + p.LastName, p.BirthDate, p.Gender, FirstViewedDate = v.FirstViewed, LastViewedDate = v.LastViewed, ViewedCount = v.ViewedCount } ); SortProperty sortProperty = gViewed.SortProperty; if ( sortProperty != null ) { qry = qry.Sort( sortProperty ); } else { qry = qry.OrderByDescending( q => q.LastViewedDate ); } gViewed.DataSource = qry.ToList(); gViewed.DataBind(); } } else { // This grid should show the profiles that have viewed this person. pnlViewed.Visible = false; pnlViewedBy.Visible = true; if ( personId.HasValue ) { var viewedList = personViewedService.Queryable() .Where( p => p.TargetPersonAlias != null && p.TargetPersonAlias.PersonId == personId ) .GroupBy( p => p.ViewerPersonAlias.PersonId ) .Select( p => new { ViewerPersonId = p.Key, FirstViewed = p.Min( g => g.ViewDateTime ), LastViewed = p.Max( g => g.ViewDateTime ), ViewedCount = p.Count() } ); var pQry = personService.Queryable(); var qry = viewedList .Join( pQry, v => v.ViewerPersonId, p => p.Id, ( v, p ) => new { p.Id, FullName = p.NickName + " " + p.LastName, p.BirthDate, p.Gender, FirstViewedDate = v.FirstViewed, LastViewedDate = v.LastViewed, ViewedCount = v.ViewedCount } ); SortProperty sortProperty = gViewedBy.SortProperty; if ( sortProperty != null ) { qry = qry.Sort( sortProperty ); } else { qry = qry.OrderByDescending( q => q.LastViewedDate ); } gViewedBy.DataSource = qry.ToList(); gViewedBy.DataBind(); } } }