/// <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();
        }
示例#2
0
        /// <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();
        }
示例#3
0
        /// <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 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(ppPage.SelectedValue);

            pageRoute.PageId = selectedPageId;

            if (!pageRoute.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            pageRouteService.Save(pageRoute, CurrentPersonId);

            // 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();
        }
示例#5
0
        /// <summary>
        /// Recursively saves Pages and associated Blocks, PageRoutes and PageContexts.
        /// </summary>
        /// <param name="page">The current Page to save</param>
        /// <param name="newBlockTypes">List of BlockTypes not currently installed</param>
        /// <param name="personId">Id of the Person performing the "Import" operation</param>
        /// <param name="parentPageId">Id of the the current Page's parent</param>
        /// <param name="siteId">Id of the site the current Page is being imported into</param>
        private void SavePages(Page page, IEnumerable <BlockType> newBlockTypes, int personId, int parentPageId, int siteId)
        {
            // find layout
            var layoutService = new LayoutService();
            var layout        = layoutService.GetBySiteId(siteId).Where(l => l.Name == page.Layout.Name && l.FileName == page.Layout.FileName).FirstOrDefault();

            if (layout == null)
            {
                layout          = new Layout();
                layout.FileName = page.Layout.FileName;
                layout.Name     = page.Layout.Name;
                layout.SiteId   = siteId;
                layoutService.Add(layout, null);
                layoutService.Save(layout, null);
            }
            int layoutId = layout.Id;

            // Force shallow copies on entities so save operations are more atomic and don't get hosed
            // by nested object references.
            var pg         = page.Clone(deepCopy: false);
            var blockTypes = newBlockTypes.ToList();

            pg.ParentPageId = parentPageId;
            pg.LayoutId     = layoutId;

            var pageService = new PageService();

            pageService.Add(pg, personId);
            pageService.Save(pg, personId);

            var blockService = new BlockService();

            foreach (var block in page.Blocks ?? new List <Block>())
            {
                var blockType = blockTypes.FirstOrDefault(bt => block.BlockType.Path == bt.Path);
                var b         = block.Clone(deepCopy: false);
                b.PageId = pg.Id;

                if (blockType != null)
                {
                    b.BlockTypeId = blockType.Id;
                }

                blockService.Add(b, personId);
                blockService.Save(b, personId);
            }

            var pageRouteService = new PageRouteService();

            foreach (var pageRoute in page.PageRoutes ?? new List <PageRoute>())
            {
                var pr = pageRoute.Clone(deepCopy: false);
                pr.PageId = pg.Id;
                pageRouteService.Add(pr, personId);
                pageRouteService.Save(pr, personId);
            }

            var pageContextService = new PageContextService();

            foreach (var pageContext in page.PageContexts ?? new List <PageContext>())
            {
                var pc = pageContext.Clone(deepCopy: false);
                pc.PageId = pg.Id;
                pageContextService.Add(pc, personId);
                pageContextService.Save(pc, personId);
            }

            foreach (var p in page.Pages ?? new List <Page>())
            {
                SavePages(p, blockTypes, personId, pg.Id, siteId);
            }
        }