/// <summary> /// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e ) { PageRoute pageRoute; PageRouteService pageRouteService = new PageRouteService(); int pageRouteId = int.Parse( hfPageRouteId.Value ); if ( pageRouteId == 0 ) { pageRoute = new PageRoute(); pageRouteService.Add( pageRoute, CurrentPersonId ); } else { pageRoute = pageRouteService.Get( pageRouteId ); } pageRoute.Route = tbRoute.Text.Trim(); int selectedPageId = int.Parse( ddlPageName.SelectedValue ); pageRoute.PageId = selectedPageId; // check for duplicates if ( pageRouteService.Queryable().Count( a => a.Route.Equals( pageRoute.Route, StringComparison.OrdinalIgnoreCase ) && !a.Id.Equals( pageRoute.Id ) ) > 0 ) { nbMessage.Text = WarningMessage.DuplicateFoundMessage( "route", Rock.Model.Page.FriendlyTypeName ); nbMessage.Visible = true; return; } if ( !pageRoute.IsValid ) { // Controls will render the error messages return; } pageRouteService.Save( pageRoute, CurrentPersonId ); RemovePageRoute( pageRoute ); // new or updated route RouteTable.Routes.AddPageRoute( pageRoute ); BindGrid(); pnlDetails.Visible = false; pnlList.Visible = true; }
/// <summary> /// Handles the Delete event of the gPageRoutes 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 gPageRoutes_Delete( object sender, RowEventArgs e ) { var rockContext = new RockContext(); PageRouteService pageRouteService = new PageRouteService( rockContext ); PageRoute pageRoute = pageRouteService.Get( e.RowKeyId ); if ( pageRoute != null ) { string errorMessage; if ( !pageRouteService.CanDelete( pageRoute, out errorMessage ) ) { mdGridWarning.Show( errorMessage, ModalAlertType.Information ); return; } pageRouteService.Delete( pageRoute ); rockContext.SaveChanges(); } BindGrid(); }
/// <summary> /// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e ) { PageRoute pageRoute; var rockContext = new RockContext(); PageRouteService pageRouteService = new PageRouteService( rockContext ); int pageRouteId = int.Parse( hfPageRouteId.Value ); if ( pageRouteId == 0 ) { pageRoute = new PageRoute(); pageRouteService.Add( pageRoute ); } else { pageRoute = pageRouteService.Get( pageRouteId ); } pageRoute.Route = tbRoute.Text.Trim(); int selectedPageId = int.Parse( ppPage.SelectedValue ); pageRoute.PageId = selectedPageId; if ( !pageRoute.IsValid ) { // Controls will render the error messages return; } if ( pageRouteService.Queryable().Any( r => r.Route == pageRoute.Route && r.Id != pageRoute.Id ) ) { // Duplicate nbErrorMessage.Title = "Duplicate Route"; nbErrorMessage.Text = "<p>There is already an existing route with this name and route names must be unique. Please choose a different route name.</p>"; nbErrorMessage.Visible = true; } else { rockContext.SaveChanges(); // new or updated route var existingRoute = RouteTable.Routes.OfType<Route>().FirstOrDefault( a => a.RouteId() == pageRoute.Id ); if ( existingRoute != null ) { RouteTable.Routes.Remove( existingRoute ); } RouteTable.Routes.AddPageRoute( pageRoute ); NavigateToParentPage(); } }
/// <summary> /// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e ) { PageRoute pageRoute; var rockContext = new RockContext(); PageRouteService pageRouteService = new PageRouteService( rockContext ); int pageRouteId = int.Parse( hfPageRouteId.Value ); if ( pageRouteId == 0 ) { pageRoute = new PageRoute(); pageRouteService.Add( pageRoute ); } else { pageRoute = pageRouteService.Get( pageRouteId ); } pageRoute.Route = tbRoute.Text.Trim(); int selectedPageId = int.Parse( ppPage.SelectedValue ); pageRoute.PageId = selectedPageId; if ( !pageRoute.IsValid ) { // Controls will render the error messages return; } rockContext.SaveChanges(); // new or updated route var existingRoute = RouteTable.Routes.OfType<Route>().FirstOrDefault( a => a.RouteId() == pageRoute.Id ); if ( existingRoute != null ) { RouteTable.Routes.Remove( existingRoute ); } RouteTable.Routes.AddPageRoute( pageRoute ); NavigateToParentPage(); }
/// <summary> /// Shows the edit. /// </summary> /// <param name="pageRouteId">The page route id.</param> protected void ShowEdit( int pageRouteId ) { pnlList.Visible = false; pnlDetails.Visible = true; PageRouteService pageRouteService = new PageRouteService(); PageRoute pageRoute = pageRouteService.Get( pageRouteId ); bool readOnly; if ( pageRoute != null ) { hfPageRouteId.Value = pageRoute.Id.ToString(); ddlPageName.SetValue( pageRoute.PageId ); tbRoute.Text = pageRoute.Route; readOnly = pageRoute.IsSystem; if ( pageRoute.IsSystem ) { lActionTitle.Text = ActionTitle.View( PageRoute.FriendlyTypeName ); btnCancel.Text = "Close"; } else { lActionTitle.Text = ActionTitle.Edit( PageRoute.FriendlyTypeName ); btnCancel.Text = "Cancel"; } } else { lActionTitle.Text = ActionTitle.Add( PageRoute.FriendlyTypeName ); hfPageRouteId.Value = 0.ToString(); ddlPageName.SetValue( string.Empty ); tbRoute.Text = string.Empty; readOnly = false; } iconIsSystem.Visible = readOnly; ddlPageName.Enabled = !readOnly; tbRoute.ReadOnly = readOnly; btnSave.Visible = !readOnly; }
/// <summary> /// Handles the Delete event of the gPageRoutes 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 gPageRoutes_Delete( object sender, RowEventArgs e ) { PageRouteService pageRouteService = new PageRouteService(); PageRoute pageRoute = pageRouteService.Get( (int)gPageRoutes.DataKeys[e.RowIndex]["id"] ); if ( CurrentBlock != null ) { pageRouteService.Delete( pageRoute, CurrentPersonId ); pageRouteService.Save( pageRoute, CurrentPersonId ); } RemovePageRoute( pageRoute ); BindGrid(); }
/// <summary> /// Handles the Delete event of the gPageRoutes 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 gPageRoutes_Delete( object sender, RowEventArgs e ) { RockTransactionScope.WrapTransaction( () => { PageRouteService pageRouteService = new PageRouteService(); PageRoute pageRoute = pageRouteService.Get( (int)e.RowKeyValue ); if ( pageRoute != null ) { string errorMessage; if ( !pageRouteService.CanDelete( pageRoute, out errorMessage ) ) { mdGridWarning.Show( errorMessage, ModalAlertType.Information ); return; } pageRouteService.Delete( pageRoute, CurrentPersonId ); pageRouteService.Save( pageRoute, CurrentPersonId ); RemovePageRoute( pageRoute ); } } ); BindGrid(); }
/// <summary> /// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e ) { PageRoute pageRoute; var rockContext = new RockContext(); PageRouteService pageRouteService = new PageRouteService( rockContext ); int pageRouteId = int.Parse( hfPageRouteId.Value ); if ( pageRouteId == 0 ) { pageRoute = new PageRoute(); pageRouteService.Add( pageRoute ); } else { pageRoute = pageRouteService.Get( pageRouteId ); } pageRoute.Route = tbRoute.Text.Trim(); int selectedPageId = int.Parse( ppPage.SelectedValue ); pageRoute.PageId = selectedPageId; if ( !pageRoute.IsValid ) { // Controls will render the error messages return; } int? siteId = null; var pageCache = PageCache.Read( selectedPageId ); if ( pageCache != null && pageCache.Layout != null ) { siteId = pageCache.Layout.SiteId; } var duplicateRoutes = pageRouteService .Queryable().AsNoTracking() .Where( r => r.Route == pageRoute.Route && r.Id != pageRoute.Id ); if ( siteId.HasValue ) { duplicateRoutes = duplicateRoutes .Where( r => r.Page != null && r.Page.Layout != null && r.Page.Layout.SiteId == siteId.Value ); } if ( duplicateRoutes.Any() ) { // Duplicate nbErrorMessage.Title = "Duplicate Route"; nbErrorMessage.Text = "<p>There is already an existing route with this name for the selected page's site. Route names must be unique per site. Please choose a different route name.</p>"; nbErrorMessage.Visible = true; } else { rockContext.SaveChanges(); // Remove previous route var oldRoute = RouteTable.Routes.OfType<Route>().FirstOrDefault( a => a.RouteIds().Contains( pageRoute.Id ) ); if ( oldRoute != null ) { var pageAndRouteIds = oldRoute.DataTokens["PageRoutes"] as List<Rock.Web.PageAndRouteId>; pageAndRouteIds = pageAndRouteIds.Where( p => p.RouteId != pageRoute.Id ).ToList(); if ( pageAndRouteIds.Any() ) { oldRoute.DataTokens["PageRoutes"] = pageAndRouteIds; } else { RouteTable.Routes.Remove( oldRoute ); } } // Add new route var pageAndRouteId = new Rock.Web.PageAndRouteId { PageId = pageRoute.PageId, RouteId = pageRoute.Id }; var existingRoute = RouteTable.Routes.OfType<Route>().FirstOrDefault( r => r.Url == pageRoute.Route ); if ( existingRoute != null ) { var pageAndRouteIds = existingRoute.DataTokens["PageRoutes"] as List<Rock.Web.PageAndRouteId>; pageAndRouteIds.Add( pageAndRouteId ); existingRoute.DataTokens["PageRoutes"] = pageAndRouteIds; } else { var pageAndRouteIds = new List<Rock.Web.PageAndRouteId>(); pageAndRouteIds.Add( pageAndRouteId ); RouteTable.Routes.AddPageRoute( pageRoute.Route, pageAndRouteIds ); } NavigateToParentPage(); } }