/// <summary> /// Creates the control(s) neccessary for prompting user for a new value /// </summary> /// <param name="configurationValues">The configuration values.</param> /// <param name="id"></param> /// <returns> /// The control /// </returns> public override System.Web.UI.Control EditControl( Dictionary<string, ConfigurationValue> configurationValues, string id ) { var editControl = new RockDropDownList { ID = id }; SiteService siteService = new SiteService( new RockContext() ); var siteList = siteService.Queryable().OrderBy( a => a.Name ).ToList(); if ( siteList.Any() ) { foreach ( var site in siteList ) { editControl.Items.Add( new ListItem( site.Name, site.Id.ToString() ) ); } return editControl; } return null; }
/// <summary> /// Binds the sites filter. /// </summary> private void BindSitesFilter() { SiteService siteService = new SiteService( new RockContext() ); ddlSite.DataTextField = "Name"; ddlSite.DataValueField = "Id"; ddlSite.DataSource = siteService.Queryable().OrderBy( s => s.Name ).ToList(); ddlSite.DataBind(); ddlSite.Items.Insert( 0, new ListItem( All.Text, All.IdValue ) ); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { SiteService siteService = new SiteService(); gSites.DataSource = siteService.Queryable().OrderBy( s => s.Name ).ToList(); gSites.DataBind(); }
/// <summary> /// Handles the Delete event of the gPages control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gPages_Delete( object sender, RowEventArgs e ) { var rockContext = new RockContext(); PageService pageService = new PageService( rockContext ); var pageViewService = new PageViewService(rockContext); var siteService = new SiteService(rockContext); Rock.Model.Page page = pageService.Get( new Guid( e.RowKeyValue.ToString() ) ); if ( page != null ) { string errorMessage; if ( !pageService.CanDelete( page, out errorMessage, includeSecondLvl: true ) ) { mdGridWarning.Show( errorMessage, ModalAlertType.Alert ); return; } foreach (var site in siteService.Queryable()) { if (site.DefaultPageId == page.Id) { site.DefaultPageId = null; site.DefaultPageRouteId = null; } if (site.LoginPageId == page.Id) { site.LoginPageId = null; site.LoginPageRouteId = null; } if (site.RegistrationPageId == page.Id) { site.RegistrationPageId = null; site.RegistrationPageRouteId = null; } } foreach (var pageView in pageViewService.GetByPageId(page.Id)) { pageView.Page = null; pageView.PageId = null; } pageService.Delete( page ); rockContext.SaveChanges(); PageCache.Flush( page.Id ); } BindPagesGrid(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { SiteService siteService = new SiteService( new RockContext() ); SortProperty sortProperty = gSites.SortProperty; var qry = siteService.Queryable(); if ( sortProperty != null ) { gSites.DataSource = qry.Sort(sortProperty).ToList(); } else { gSites.DataSource = qry.OrderBy( s => s.Name ).ToList(); } gSites.EntityTypeId = EntityTypeCache.Read<Site>().Id; gSites.DataBind(); }
/// <summary> /// Handles the Delete event of the rGrid control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param> protected void rGrid_Delete( object sender, RowEventArgs e ) { var rockContext = new RockContext(); var pageService = new PageService( rockContext ); var pageViewService = new PageViewService( rockContext ); var siteService = new SiteService( rockContext ); var page = pageService.Get( e.RowKeyId ); if ( page != null ) { string errorMessage = string.Empty; if ( !pageService.CanDelete( page, out errorMessage ) ) { mdDeleteWarning.Show( errorMessage, ModalAlertType.Alert ); return; } foreach ( var site in siteService.Queryable() ) { if ( site.DefaultPageId == page.Id ) { site.DefaultPageId = null; site.DefaultPageRouteId = null; } if ( site.LoginPageId == page.Id ) { site.LoginPageId = null; site.LoginPageRouteId = null; } if ( site.RegistrationPageId == page.Id ) { site.RegistrationPageId = null; site.RegistrationPageRouteId = null; } } foreach ( var pageView in pageViewService.GetByPageId( page.Id ) ) { pageView.Page = null; pageView.PageId = null; } pageService.Delete( page ); rockContext.SaveChanges(); Rock.Web.Cache.PageCache.Flush( page.Id ); if ( _page != null ) { _page.FlushChildPages(); } } BindGrid(); }
/// <summary> /// Cleans up PagesViews for sites that have a Page View retention period /// </summary> /// <param name="dataMap">The data map.</param> private int CleanupPageViews( JobDataMap dataMap ) { var pageViewRockContext = new Rock.Data.RockContext(); var currentDateTime = RockDateTime.Now; var siteService = new SiteService( pageViewRockContext ); var siteQry = siteService.Queryable().Where( a => a.PageViewRetentionPeriodDays.HasValue ); int totalRowsDeleted = 0; // foreach ( var site in siteQry.ToList() ) { var retentionCutoffDateTime = currentDateTime.AddDays( -site.PageViewRetentionPeriodDays.Value ); if ( retentionCutoffDateTime < System.Data.SqlTypes.SqlDateTime.MinValue.Value ) { retentionCutoffDateTime = System.Data.SqlTypes.SqlDateTime.MinValue.Value; } // delete in chunks (see http://dba.stackexchange.com/questions/1750/methods-of-speeding-up-a-huge-delete-from-table-with-no-clauses) bool keepDeleting = true; while ( keepDeleting ) { var dbTransaction = pageViewRockContext.Database.BeginTransaction(); try { string sqlCommand = @"DELETE TOP (1000) FROM [PageView] WHERE [SiteId] = @siteId AND DateTimeViewed < @retentionCutoffDateTime"; int rowsDeleted = pageViewRockContext.Database.ExecuteSqlCommand( sqlCommand, new SqlParameter( "siteId", site.Id ), new SqlParameter( "retentionCutoffDateTime", retentionCutoffDateTime ) ); keepDeleting = rowsDeleted > 0; totalRowsDeleted += rowsDeleted; } finally { dbTransaction.Commit(); } } } return totalRowsDeleted; }
protected void rGrid_Delete( object sender, RowEventArgs e ) { using ( new UnitOfWorkScope() ) { var pageService = new PageService(); var siteService = new SiteService(); var page = pageService.Get( (int)rGrid.DataKeys[e.RowIndex]["id"] ); if ( page != null ) { RockTransactionScope.WrapTransaction( () => { foreach ( var site in siteService.Queryable() ) { bool updateSite = false; if (site.DefaultPageId == page.Id) { site.DefaultPageId = null; site.DefaultPageRouteId = null; updateSite = true; } if (site.LoginPageId == page.Id) { site.LoginPageId = null; site.LoginPageRouteId = null; updateSite = true; } if (site.RegistrationPageId == page.Id) { site.RegistrationPageId = null; site.RegistrationPageRouteId = null; updateSite = true; } if (updateSite) { siteService.Save( site, CurrentPersonId ); } } pageService.Delete( page, CurrentPersonId ); pageService.Save( page, CurrentPersonId ); Rock.Web.Cache.PageCache.Flush( page.Id ); if ( _page != null ) _page.FlushChildPages(); } ); } } BindGrid(); }
protected void rGrid_Delete( object sender, RowEventArgs e ) { var rockContext = new RockContext(); var pageService = new PageService( rockContext ); var pageViewService = new PageViewService( rockContext ); var siteService = new SiteService( rockContext ); var page = pageService.Get( (int)rGrid.DataKeys[e.RowIndex]["id"] ); if ( page != null ) { string errorMessage = string.Empty; if ( !pageService.CanDelete( page, out errorMessage ) ) { //errorMessage = "The page is the parent page of another page."; mdDeleteWarning.Show( errorMessage, ModalAlertType.Alert ); return; } foreach ( var site in siteService.Queryable() ) { if ( site.DefaultPageId == page.Id ) { site.DefaultPageId = null; site.DefaultPageRouteId = null; } if ( site.LoginPageId == page.Id ) { site.LoginPageId = null; site.LoginPageRouteId = null; } if ( site.RegistrationPageId == page.Id ) { site.RegistrationPageId = null; site.RegistrationPageRouteId = null; } } // TODO: Could be thousands of page views. Can we set this up as cascade? foreach( var pageView in pageViewService.GetByPageId(page.Id)) { pageViewService.Delete( pageView ); } pageService.Delete( page ); rockContext.SaveChanges(); Rock.Web.Cache.PageCache.Flush( page.Id ); if ( _page != null ) { _page.FlushChildPages(); } } BindGrid(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { SiteService siteService = new SiteService(); SortProperty sortProperty = gSites.SortProperty; var qry = siteService.Queryable(); if ( sortProperty != null ) { gSites.DataSource = qry.Sort(sortProperty).ToList(); } else { gSites.DataSource = qry.OrderBy( s => s.Name ).ToList(); } gSites.DataBind(); }