Ejemplo n.º 1
0
        /// <summary>
        /// Handles the Click event of the DeleteLayout control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs" /> instance containing the event data.</param>
        protected void DeleteLayout_Click(object sender, Rock.Web.UI.Controls.RowEventArgs e)
        {
            RockTransactionScope.WrapTransaction(() =>
            {
                LayoutService layoutService = new LayoutService();
                Layout layout = layoutService.Get(e.RowKeyId);
                if (layout != null)
                {
                    string errorMessage;
                    if (!layoutService.CanDelete(layout, out errorMessage))
                    {
                        mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }

                    int siteId = layout.SiteId;

                    layoutService.Delete(layout, CurrentPersonId);
                    layoutService.Save(layout, CurrentPersonId);

                    LayoutCache.Flush(e.RowKeyId);
                }
            });

            BindLayoutsGrid();
        }
Ejemplo n.º 2
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)
        {
            if (Page.IsValid)
            {
                LayoutService layoutService = new LayoutService();
                Layout        layout;

                int layoutId = int.Parse(hfLayoutId.Value);

                // if adding a new layout
                if (layoutId.Equals(0))
                {
                    layout = new Layout {
                        Id = 0
                    };
                    layout.SiteId = hfSiteId.ValueAsInt();
                }
                else
                {
                    //load existing group member
                    layout = layoutService.Get(layoutId);
                }

                layout.Name        = tbLayoutName.Text;
                layout.Description = tbDescription.Text;
                layout.FileName    = ddlLayout.SelectedValue;

                if (!layout.IsValid)
                {
                    return;
                }

                RockTransactionScope.WrapTransaction(() =>
                {
                    if (layout.Id.Equals(0))
                    {
                        layoutService.Add(layout, CurrentPersonId);
                    }

                    layoutService.Save(layout, CurrentPersonId);
                });

                LayoutCache.Flush(layout.Id);

                Dictionary <string, string> qryString = new Dictionary <string, string>();
                qryString["siteId"] = hfSiteId.Value;
                NavigateToParentPage(qryString);
            }
        }
Ejemplo n.º 3
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);
            }
        }