/// <summary> /// Handles the Click event of the btnDeleteConfirm control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnDeleteConfirm_Click( object sender, EventArgs e ) { bool canDelete = false; var rockContext = new RockContext(); SiteService siteService = new SiteService( rockContext ); Site site = siteService.Get( int.Parse( hfSiteId.Value ) ); LayoutService layoutService = new LayoutService( rockContext ); PageService pageService = new PageService( rockContext ); PageViewService pageViewService = new PageViewService( rockContext ); if ( site != null ) { var sitePages = new List<int> { site.DefaultPageId ?? -1, site.LoginPageId ?? -1, site.RegistrationPageId ?? -1, site.PageNotFoundPageId ?? -1 }; foreach ( var pageView in pageViewService .Queryable() .Where( t => t.Page != null && t.Page.Layout != null && t.Page.Layout.SiteId == site.Id ) ) { pageView.Page = null; pageView.PageId = null; } var pageQry = pageService.Queryable( "Layout" ) .Where( t => t.Layout.SiteId == site.Id || sitePages.Contains( t.Id ) ); pageService.DeleteRange( pageQry ); var layoutQry = layoutService.Queryable() .Where( l => l.SiteId == site.Id ); layoutService.DeleteRange( layoutQry ); rockContext.SaveChanges( true ); string errorMessage; canDelete = siteService.CanDelete( site, out errorMessage, includeSecondLvl: true ); if ( !canDelete ) { mdDeleteWarning.Show( errorMessage, ModalAlertType.Alert ); return; } siteService.Delete( site ); rockContext.SaveChanges(); SiteCache.Flush( site.Id ); } NavigateToParentPage(); }
void ShowList() { var rockContext = new RockContext(); int sessionCount = Int32.Parse( GetAttributeValue( "SessionCount" ) ); int skipCount = pageNumber * sessionCount; var person = new PersonService( rockContext ).GetByUrlEncodedKey( PageParameter( "Person" ) ); if (person != null) { if ( GetAttributeValue( "ShowHeader" ).AsBoolean() ) { pnlHeader.Visible = true; lPersonName.Text = person.FullName.FormatAsHtmlTitle() + " Page Views"; } else { pnlHeader.Visible = false; } PageViewService pageviewService = new PageViewService( rockContext ); var pageViews = pageviewService.Queryable(); var sessionInfo = pageviewService.Queryable() .Where( s => s.PersonAlias.PersonId == person.Id ) .GroupBy( s => new { s.SessionId, s.SiteId, SiteName = s.Site.Name, s.ClientType, s.IpAddress, s.UserAgent }) .Select( s => new WebSession { SessionId = s.Key.SessionId, StartDateTime = s.Min(x => x.DateTimeViewed), EndDateTime = s.Max(x => x.DateTimeViewed), SiteId = s.Key.SiteId, Site = s.Key.SiteName, ClientType = s.Key.ClientType, IpAddress = s.Key.IpAddress, UserAgent = s.Key.UserAgent, PageViews = pageViews.Where(p=> p.SessionId == s.Key.SessionId).ToList() }); if ( startDate != DateTime.MinValue ) { sessionInfo = sessionInfo.Where( s => s.StartDateTime > drpDateFilter.LowerValue ); } if ( endDate != DateTime.MaxValue ) { sessionInfo = sessionInfo.Where( s => s.StartDateTime < drpDateFilter.UpperValue ); } if ( siteId != -1 ) { sessionInfo = sessionInfo.Where( s => s.SiteId == siteId ); } sessionInfo = sessionInfo.OrderByDescending(p => p.StartDateTime) .Skip( skipCount ) .Take( sessionCount + 1); rptSessions.DataSource = sessionInfo.ToList().Take(sessionCount); rptSessions.DataBind(); // set next button if ( sessionInfo.Count() > sessionCount ) { hlNext.Visible = hlNext.Enabled = true; Dictionary<string, string> queryStringNext = new Dictionary<string, string>(); queryStringNext.Add( "Page", (pageNumber + 1).ToString() ); queryStringNext.Add( "Person", person.UrlEncodedKey ); if ( siteId != -1 ) { queryStringNext.Add( "SiteId", siteId.ToString() ); } if ( startDate != DateTime.MinValue ) { queryStringNext.Add( "StartDate", startDate.ToShortDateString() ); } if ( endDate != DateTime.MaxValue ) { queryStringNext.Add( "EndDate", endDate.ToShortDateString() ); } var pageReferenceNext = new Rock.Web.PageReference( CurrentPageReference.PageId, CurrentPageReference.RouteId, queryStringNext ); hlNext.NavigateUrl = pageReferenceNext.BuildUrl(); } else { hlNext.Visible = hlNext.Enabled = false; } // set prev button if ( pageNumber == 0 ) { hlPrev.Visible = hlPrev.Enabled = false; } else { hlPrev.Visible = hlPrev.Enabled = true; Dictionary<string, string> queryStringPrev = new Dictionary<string, string>(); queryStringPrev.Add( "Page", (pageNumber - 1).ToString() ); queryStringPrev.Add( "Person", person.UrlEncodedKey ); if ( siteId != -1 ) { queryStringPrev.Add( "SiteId", siteId.ToString() ); } if ( startDate != DateTime.MinValue ) { queryStringPrev.Add( "StartDate", startDate.ToShortDateString() ); } if ( endDate != DateTime.MaxValue ) { queryStringPrev.Add( "EndDate", endDate.ToShortDateString() ); } var pageReferencePrev = new Rock.Web.PageReference( CurrentPageReference.PageId, CurrentPageReference.RouteId, queryStringPrev ); hlPrev.NavigateUrl = pageReferencePrev.BuildUrl(); } } else { lMessages.Text = "<div class='alert alert-warning'>No person provided to show results for.</div>"; } }