Пример #1
0
 public PageMappedContext(Page page, PageRoute matchedRoute, string matchedVirtualPath, string queryStringPath)
 {
     this.Page               = page;
     this.MatchedRoute       = matchedRoute;
     this.MatchedVirtualPath = matchedVirtualPath;
     this.QueryStringPath    = queryStringPath;
 }
Пример #2
0
        /// <summary>
        /// generate html for dynamic page
        /// </summary>
        /// <param name="pageRoute"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        private string Generatehtmlfile(PageRoute pageRoute, string language)
        {
            pageRoute = _pageRouteRepository.Get(pageRoute.Id);
            var pagename = pageRoute.EnName.Replace(' ', '_') + language + ".html";
            //path where the new html page will be generated in
            var      relativePath      = "\\PublishDynamicPages\\" + Guid.NewGuid() + pagename;
            string   filePath          = _IWebHostEnvironment.WebRootPath + relativePath;
            FileInfo generatedHtmlFile = new FileInfo(filePath);

            generatedHtmlFile.Directory.Create();

            //ApplyTemplateOnGeneratedHtmlFile
            FileInfo TemplateFile;

            //get the template
            TemplateFile = new FileInfo(_IWebHostEnvironment.WebRootPath + "/DynamicPageTemplate/DynamicPageTemplateAR.html");

            string Template      = TemplateFile.OpenText().ReadToEnd();
            var    TemplateParts = Template.Split("newsectionsplit");

            //list that will contain the generated section
            var sections = new List <string>();
            //get the sections that will be generated
            var pageSections = _IPageSectionVersionRepository.GetPageSections(pageRoute.Id).Where(x => x.IsActive && !x.IsDeleted).OrderBy(x => x.Order);
            int i            = 0;

            foreach (var section in pageSections)
            {
                sections.Add(ApplyTemplateOnGeneratedHtmlFile(section.PageSectionTypeId, section, TemplateParts[section.PageSectionTypeId], language, i++));
            }

            StreamWriter writerInGeneratedHtmlFile = generatedHtmlFile.CreateText();

            //templateHeader marks to be replaced with the header values
            string PageTittle = "&lt;&lt;PageTittle&gt;&gt;";
            string pageNav    = "&lt;&lt;PageNav&gt;&gt;";
            string PageHome   = "&lt;&lt;PageHome&gt;&gt;";


            //write the header
            if (language.ToLower() == "en")
            {
                writerInGeneratedHtmlFile.WriteLine(TemplateParts[0].Replace(PageTittle, pageRoute.EnName).Replace(pageNav, pageRoute.NavItem.EnName).Replace(PageHome, "Home"));
            }
            else
            {
                writerInGeneratedHtmlFile.WriteLine(TemplateParts[0].Replace(PageTittle, pageRoute.ArName).Replace(pageNav, pageRoute.NavItem.ArName).Replace(PageHome, "الرئيسية"));
            }

            //write sections
            foreach (var section in sections)
            {
                writerInGeneratedHtmlFile.WriteLine(section);
            }

            //templateFooterandCSS
            writerInGeneratedHtmlFile.WriteLine(TemplateParts[9]);
            writerInGeneratedHtmlFile.Close();
            return(relativePath);
        }
Пример #3
0
        private PageDetails Map(
            PageVersion dbPageVersion,
            ICollection <PageRegionDetails> regions,
            PageRoute pageRoute
            )
        {
            var page = new PageDetails();

            page.PageId    = dbPageVersion.PageId;
            page.PageRoute = pageRoute;
            page.AuditData = _auditDataMapper.MapCreateAuditData(dbPageVersion.Page);
            page.Tags      = dbPageVersion
                             .Page
                             .PageTags
                             .Select(t => t.Tag.TagText)
                             .OrderBy(t => t)
                             .ToList();

            page.LatestVersion = new PageVersionDetails()
            {
                MetaDescription = dbPageVersion.MetaDescription,
                PageVersionId   = dbPageVersion.PageVersionId,
                ShowInSiteMap   = !dbPageVersion.ExcludeFromSitemap,
                DisplayVersion  = dbPageVersion.DisplayVersion,
                Title           = dbPageVersion.Title,
                WorkFlowStatus  = (WorkFlowStatus)dbPageVersion.WorkFlowStatusId
            };

            page.LatestVersion.AuditData = _auditDataMapper.MapCreateAuditData(dbPageVersion);
            page.LatestVersion.OpenGraph = _openGraphDataMapper.Map(dbPageVersion);
            page.LatestVersion.Template  = _pageTemplateMapper.Map(dbPageVersion.PageTemplate);
            page.LatestVersion.Regions   = regions;

            return(page);
        }
Пример #4
0
        public IActionResult Index(int pageRouteId)
        {
            if (TempData[notificationMessageKey] != null)
            {
                switch (TempData[notificationTypeKey])
                {
                case notificationSuccess:
                    _toastNotification.AddSuccessToastMessage(TempData[notificationMessageKey].ToString());
                    break;

                case notificationWarning:
                    _toastNotification.AddWarningToastMessage(TempData[notificationMessageKey].ToString());
                    break;

                case notificationError:
                    _toastNotification.AddErrorToastMessage(TempData[notificationMessageKey].ToString());
                    break;
                }
            }

            PageRoute pageRoute = _pageRouteRepository.Get(pageRouteId);

            if (pageRoute == null)
            {
                return(NotFound());
            }

            return(View(pageRouteId));
        }
Пример #5
0
        Widget buildPageTransitions(
            PageRoute route,
            BuildContext context,
            Animation <float> animation,
            Animation <float> secondaryAnimation,
            Widget child
            )
        {
            if (route.fullscreenDialog)
            {
                return(new CustomFullscreenDialogTransition(
                           animation: animation,
                           child: child
                           ));
            }

            if (this.push)
            {
                return(new PushPageTransition(
                           animation: animation,
                           child: child
                           ));
            }

            return(new CustomPageTransition(
                       primaryRouteAnimation: animation,
                       secondaryRouteAnimation: secondaryAnimation,
                       linearTransition: isPopGestureInProgress(route),
                       child: new _CustomPageBackGestureDetector(
                           enabledCallback: () => _isPopGestureEnabled(route),
                           onStartPopGesture: () => _startPopGesture(route),
                           child: child
                           )
                       ));
        }
        /// <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();
        }
Пример #7
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            nbErrorMessage.Visible = false;

            var pageRouteId = PageParameter("pageRouteId").AsInteger();

            if (!Page.IsPostBack)
            {
                ShowDetail(pageRouteId);
            }

            // Add any attribute controls.
            // This must be done here regardless of whether it is a postback so that the attribute values will get saved.
            var pageRoute = new PageRouteService(new RockContext()).Get(pageRouteId);

            if (pageRoute == null)
            {
                pageRoute = new PageRoute();
            }
            if (!pageRoute.IsSystem)
            {
                pageRoute.LoadAttributes();
                phAttributes.Controls.Clear();
                Helper.AddEditControls(pageRoute, phAttributes, true, BlockValidationGroup);
            }
        }
Пример #8
0
        public async Task Add(IEnumerable <PageDto> pagesDto)
        {
            foreach (var pageDto in pagesDto)
            {
                pageDto.Content = pageDto.Content.TrimScript();
                pageDto.Content = await _htmlContentService.SavePictures(pageDto.Content);
            }

            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <PageDto, Page>()
                                                 .ForMember(c => c.Content, opt => opt.MapFrom(n => n.Content.ToString())))
                         .CreateMapper();
            var pages = mapper.Map <IEnumerable <PageDto>, IEnumerable <Page> >(pagesDto);

            var route = new PageRoute()
            {
                Route = pagesDto.FirstOrDefault().Route
            };

            (pages as List <Page>).ForEach(p => p.PageRoute = route);

            try
            {
                _unitOfWork.Repository <Page>().AddRange(pages);
                await _unitOfWork.SaveChangesAsync();
            }
            catch (Exception e)
            {
                e.Data["page"] = pagesDto;
                throw;
            }
        }
Пример #9
0
        public static Widget buildPageTransitions(
            PageRoute route,
            BuildContext context,
            Animation <float> animation,
            Animation <float> secondaryAnimation,
            Widget child
            )
        {
            bool linearTransition = isPopGestureInProgress(route);

            if (route.fullscreenDialog)
            {
                return(new CupertinoFullscreenDialogTransition(
                           primaryRouteAnimation: animation,
                           secondaryRouteAnimation: secondaryAnimation,
                           child: child,
                           linearTransition: linearTransition
                           ));
            }

            else
            {
                return(new CupertinoPageTransition(
                           primaryRouteAnimation: animation,
                           secondaryRouteAnimation: secondaryAnimation,
                           linearTransition: linearTransition,
                           child: new _CupertinoBackGestureDetector(
                               enabledCallback: () => _isPopGestureEnabled(route),
                               onStartPopGesture: () => _startPopGesture(route),
                               child: child
                               )
                           ));
            }
        }
Пример #10
0
        public static PageRouteVersion MapToPageRouteVersion(this PageRoute pageRoute)
        {
            PageRouteVersion pageRouteVersion = new PageRouteVersion()
            {
                ApprovalDate   = pageRoute.ApprovalDate,
                ApprovedById   = pageRoute.ApprovedById,
                ArName         = pageRoute.ArName,
                EnName         = pageRoute.EnName,
                IsActive       = pageRoute.IsActive,
                IsDeleted      = pageRoute.IsDeleted,
                Order          = pageRoute.Order,
                NavItemId      = pageRoute.NavItemId,
                ControllerName = pageRoute.ControllerName,
                SectionName    = pageRoute.SectionName,
                CreationDate   = pageRoute.CreationDate,
                CreatedById    = pageRoute.CreatedById,
                IsDynamicPage  = pageRoute.IsDynamicPage,

                SeoTitleEN       = pageRoute.SeoTitleEN,
                SeoTitleAR       = pageRoute.SeoTitleAR,
                SeoDescriptionEN = pageRoute.SeoDescriptionEN,
                SeoDescriptionAR = pageRoute.SeoDescriptionAR,
                SeoOgTitleEN     = pageRoute.SeoOgTitleEN,
                SeoOgTitleAR     = pageRoute.SeoOgTitleAR,
                SeoTwitterCardEN = pageRoute.SeoTwitterCardEN,
                SeoTwitterCardAR = pageRoute.SeoTwitterCardAR,
            };

            return(pageRouteVersion);
        }
Пример #11
0
        /// <summary>
        /// create ar and en dynamic page for specefic page route
        /// </summary>
        /// <param name="id"></param>
        /// <param name="pageRoute"></param>
        public void ApplyPageChanges(int id, PageRoute pageRoute)
        {
            pageRoute.PageFilePathAr = Generatehtmlfile(pageRoute, "ar");
            pageRoute.PageFilePathEn = Generatehtmlfile(pageRoute, "en");

            _pageRouteVersionRepository.ApplyEditRequest(id, pageRoute.PageFilePathAr, pageRoute.PageFilePathEn);
            _pageRouteRepository.UpdatePageRoute(pageRoute);
        }
Пример #12
0
 /// <summary>
 /// Adds the page route.
 /// </summary>
 /// <param name="routes">The routes.</param>
 /// <param name="pageRoute">The page route.</param>
 public static void AddPageRoute( this Collection<RouteBase> routes, PageRoute pageRoute )
 {
     Route route = new Route( pageRoute.Route, new Rock.Web.RockRouteHandler() );
     route.DataTokens = new RouteValueDictionary();
     route.DataTokens.Add( "PageId", pageRoute.PageId.ToString() );
     route.DataTokens.Add( "RouteId", pageRoute.Id.ToString() );
     routes.Add( route );
 }
Пример #13
0
 static _CupertinoBackGestureController _startPopGesture(PageRoute route)
 {
     D.assert(_isPopGestureEnabled(route));
     return(new _CupertinoBackGestureController(
                navigator: route.navigator,
                controller: route.controller
                ));
 }
        protected override void OnParametersSet()
        {
            if (PageRoute is null)
            {
                return;
            }
            if (LocalStorage is null)
            {
                return;
            }

            if (MyText is null)
            {
                return;
            }


            var s = PageRoute.Split('/');

            if (s.Length == 2)
            {
                UserId = s[0];
                Token  = s[1];
            }

            if (string.IsNullOrEmpty(UserId))
            {
                return;
            }
            if (string.IsNullOrEmpty(Token))
            {
                return;
            }

            User.UserId = UserId;
            User.Token  = Token;

            try
            {
                var token = LocalStorage.GetItem <Token>(Const.TokenKey);

                Dispatcher?.Dispatch(
                    new UsersCreationConfirmAction(
                        user: User,
                        token: token.AuthToken,
                        userPasswordResetConfirmMessage: MyText?.PasswordReseted ?? string.Empty));

                if (NavigationManager is null)
                {
                    return;
                }
                NavigationManager.NavigateTo("/");
            }
            catch
            {
                ShowAlert(MyText?.DataSavedNOk ?? string.Empty);
            }
        }
Пример #15
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="routeId">The route identifier.</param>
        public void ShowDetail(int routeId)
        {
            pnlDetails.Visible = true;

            PageRoute pageRoute = null;

            if (!routeId.Equals(0))
            {
                pageRoute         = new PageRouteService(new RockContext()).Get(routeId);
                lActionTitle.Text = ActionTitle.Edit(PageRoute.FriendlyTypeName).FormatAsHtmlTitle();
                pdAuditDetails.SetEntity(pageRoute, ResolveRockUrl("~"));
            }

            if (pageRoute == null)
            {
                pageRoute = new PageRoute {
                    Id = 0
                };
                lActionTitle.Text = ActionTitle.Add(PageRoute.FriendlyTypeName).FormatAsHtmlTitle();
                // hide the panel drawer that show created and last modified dates
                pdAuditDetails.Visible = false;
            }

            hfPageRouteId.Value = pageRoute.Id.ToString();
            ppPage.SetValue(pageRoute.Page);

            ShowSite();

            tbRoute.Text       = pageRoute.Route;
            cbIsGlobal.Checked = pageRoute.IsGlobal;

            // render UI based on Authorized and IsSystem. Do IsSystem check first so the IsUserAuthorized check can overwrite the settings.
            nbEditModeMessage.Text = string.Empty;

            if (pageRoute.IsSystem)
            {
                nbEditModeMessage.Text = EditModeMessage.System(PageRoute.FriendlyTypeName);

                ppPage.Enabled     = false;
                tbRoute.ReadOnly   = true;
                cbIsGlobal.Enabled = true;
                btnSave.Visible    = true;
            }

            if (!IsUserAuthorized(Authorization.EDIT))
            {
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(PageRoute.FriendlyTypeName);

                lActionTitle.Text = ActionTitle.View(PageRoute.FriendlyTypeName).FormatAsHtmlTitle();
                btnCancel.Text    = "Close";

                ppPage.Enabled     = false;
                tbRoute.ReadOnly   = true;
                cbIsGlobal.Enabled = false;
                btnSave.Visible    = false;
            }
        }
Пример #16
0
        public void ShallowClone()
        {
            var pageRoute = new PageRoute {
                Guid = Guid.NewGuid()
            };
            var result = pageRoute.Clone(false);

            Assert.That.AreEqual(result.Guid, pageRoute.Guid);
        }
Пример #17
0
        /// <summary>
        /// Adds the page route.
        /// </summary>
        /// <param name="routes">The routes.</param>
        /// <param name="pageRoute">The page route.</param>
        public static void AddPageRoute(this Collection <RouteBase> routes, PageRoute pageRoute)
        {
            Route route = new Route(pageRoute.Route, new Rock.Web.RockRouteHandler());

            route.DataTokens = new RouteValueDictionary();
            route.DataTokens.Add("PageId", pageRoute.PageId.ToString());
            route.DataTokens.Add("RouteId", pageRoute.Id.ToString());
            routes.Add(route);
        }
Пример #18
0
        public void ToJson()
        {
            var pageRoute = new PageRoute {
                Guid = Guid.NewGuid()
            };
            dynamic result = pageRoute.ToJson();

            Assert.That.IsNotEmpty(result as string);
        }
Пример #19
0
 public bool Open(PageRoute route)
 {
     if (route.Context == null)
     {
         return(TryNotice.Current.Show(false, $"{nameof(route.Context)}参数配置异常"));
     }
     Open(route.Context.ToString());
     return(true);
 }
Пример #20
0
        /// <summary>
        /// Removes the page route.
        /// </summary>
        /// <param name="pageRoute">The page route.</param>
        private static void RemovePageRoute(PageRoute pageRoute)
        {
            var existingRoute = RouteTable.Routes.OfType <Route>().FirstOrDefault(a => a.RouteId() == pageRoute.Id);

            if (existingRoute != null)
            {
                RouteTable.Routes.Remove(existingRoute);
            }
        }
Пример #21
0
            public void ShouldCopyEntity()
            {
                var pageRoute = new PageRoute {
                    Guid = Guid.NewGuid()
                };
                var result = pageRoute.Clone(false);

                Assert.AreEqual(result.Guid, pageRoute.Guid);
            }
 private PageRoutingInfo ToRoutingInfo(PageRoute pageRoute, CustomEntityRoute customEntityRoute = null, ICustomEntityRoutingRule rule = null)
 {
     return(new PageRoutingInfo()
     {
         PageRoute = pageRoute,
         CustomEntityRoute = customEntityRoute,
         CustomEntityRouteRule = rule
     });
 }
Пример #23
0
            public void ShouldCopyEntity()
            {
                var pageRoute = new PageRoute {
                    Guid = Guid.NewGuid()
                };
                dynamic result = pageRoute.ExportObject();

                Assert.AreEqual(result.Guid, pageRoute.Guid);
            }
Пример #24
0
        public string RenderSystemLink(RenderContext context, Routing.Route route)
        {
            Render.FrontContext frontContext = context.GetItem <Render.FrontContext>();

            route.Parameters = ObjectRoute.ParseParameters(route, this.Url);

            var  constTypeString = route.Parameters.GetValue("objecttype");
            byte constType       = ConstObjectType.Unknown;

            if (!byte.TryParse(constTypeString, out constType))
            {
                constType = ConstTypeContainer.GetConstType(constTypeString);
            }
            var id = route.Parameters.GetValue("nameorid");

            if (constType == ConstObjectType.View)
            {
                var view = context.WebSite.SiteDb().Views.GetByNameOrId(id);

                if (view != null)
                {
                    var relation = context.WebSite.SiteDb().Relations.GetReferredBy(view, ConstObjectType.Page);

                    if (relation != null && relation.Count > 0)
                    {
                        var pageid = relation[0].objectXId;

                        var pageroute = context.WebSite.SiteDb().Routes.GetByObjectId(pageid);

                        if (pageroute != null)
                        {
                            return(RenderPageRoute(context, pageroute));
                        }
                    }
                    /// if view was not rendered within and by the page... try to render with rendercode.
                    if (frontContext.Page != null && frontContext.ExecutingView != null)
                    {
                        string currenturl = context.Request.RelativeUrl;

                        var values = PageRoute.GetViewParameterValues(context.WebSite.SiteDb(), view, frontContext);

                        var alternativeviewcode = Cache.ViewInSamePosition.GetAlternativeCode(frontContext.ExecutingView.Id, view.Id);

                        values.Add(SiteConstants.AlternativeViewQueryName, alternativeviewcode.ToString());
                        return(Kooboo.Lib.Helper.UrlHelper.AppendQueryString(currenturl, values));
                    }

                    else if (frontContext.Page == null)
                    {
                        var values = PageRoute.GetViewParameterValues(context.WebSite.SiteDb(), view, frontContext);

                        return(Kooboo.Lib.Helper.UrlHelper.AppendQueryString(this.Url, values));
                    }
                }
            }
            return(null);
        }
Пример #25
0
            public void ShouldNotBeEmpty()
            {
                var pageRoute = new PageRoute {
                    Guid = Guid.NewGuid()
                };
                dynamic result = pageRoute.ToJson();

                Assert.IsNotEmpty(result);
            }
Пример #26
0
 public override Widget buildTransitions(
     PageRoute route,
     BuildContext context,
     Animation <float> animation,
     Animation <float> secondaryAnimation,
     Widget child
     )
 {
     return(CupertinoPageRoute.buildPageTransitions(route, context, animation, secondaryAnimation, child));
 }
        private Task OnTransactionComplete(PageRoute page)
        {
            _pageCache.Clear(page.PageId);

            return(_messageAggregator.PublishAsync(new PageDeletedMessage()
            {
                PageId = page.PageId,
                FullUrlPath = page.FullUrlPath
            }));
        }
Пример #28
0
        private SiteMapResource MapPageResource(PageRoute pageRoute)
        {
            var version  = pageRoute.Versions.GetVersionRouting(PublishStatusQuery.Published);
            var resource = new SiteMapResource();

            resource.Url = pageRoute.FullPath;
            resource.LastModifiedDate = pageRoute.PublishDate;
            resource.Priority         = GetPriority(pageRoute);

            return(resource);
        }
Пример #29
0
        public Widget buildTranstions(
            PageRoute route,
            BuildContext context,
            Animation <float> animation,
            Animation <float> secondaryAnimation,
            Widget child)
        {
            PageTransitionsBuilder matchingBuilder = builder;

            return(matchingBuilder.buildTransitions(route, context, animation, secondaryAnimation, child));
        }
Пример #30
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="routeId">The route identifier.</param>
        public void ShowDetail( int routeId )
        {
            pnlDetails.Visible = true;

            PageRoute pageRoute = null;

            if ( !routeId.Equals( 0 ) )
            {
                pageRoute = new PageRouteService( new RockContext() ).Get( routeId );
                lActionTitle.Text = ActionTitle.Edit( PageRoute.FriendlyTypeName ).FormatAsHtmlTitle();
                pdAuditDetails.SetEntity( pageRoute, ResolveRockUrl( "~" ) );
            }

            if (pageRoute == null)
            {
                pageRoute = new PageRoute { Id = 0 };
                lActionTitle.Text = ActionTitle.Add(PageRoute.FriendlyTypeName).FormatAsHtmlTitle();
                // hide the panel drawer that show created and last modified dates
                pdAuditDetails.Visible = false;
            }

            hfPageRouteId.Value = pageRoute.Id.ToString();
            ppPage.SetValue( pageRoute.Page );

            ShowSite();

            tbRoute.Text = pageRoute.Route;

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if ( !IsUserAuthorized( Authorization.EDIT ) )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( PageRoute.FriendlyTypeName );
            }

            if ( pageRoute.IsSystem )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( PageRoute.FriendlyTypeName );
            }

            if ( readOnly )
            {
                lActionTitle.Text = ActionTitle.View( PageRoute.FriendlyTypeName ).FormatAsHtmlTitle();
                btnCancel.Text = "Close";
            }

            ppPage.Enabled = !readOnly;
            tbRoute.ReadOnly = readOnly;
            btnSave.Visible = !readOnly;
        }
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="itemKey">The item key.</param>
        /// <param name="itemKeyValue">The item key value.</param>
        public void ShowDetail(string itemKey, int itemKeyValue)
        {
            if (!itemKey.Equals("pageRouteId"))
            {
                return;
            }

            pnlDetails.Visible = true;

            PageRoute pageRoute = null;

            if (!itemKeyValue.Equals(0))
            {
                pageRoute         = new PageRouteService().Get(itemKeyValue);
                lActionTitle.Text = ActionTitle.Edit(PageRoute.FriendlyTypeName);
            }
            else
            {
                pageRoute = new PageRoute {
                    Id = 0
                };
                lActionTitle.Text = ActionTitle.Add(PageRoute.FriendlyTypeName);
            }

            hfPageRouteId.Value = pageRoute.Id.ToString();
            ppPage.SetValue(pageRoute.Page);
            tbRoute.Text = pageRoute.Route;

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if (!IsUserAuthorized("Edit"))
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(PageRoute.FriendlyTypeName);
            }

            if (pageRoute.IsSystem)
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem(PageRoute.FriendlyTypeName);
            }

            if (readOnly)
            {
                lActionTitle.Text = ActionTitle.View(PageRoute.FriendlyTypeName);
                btnCancel.Text    = "Close";
            }

            ppPage.Enabled   = !readOnly;
            tbRoute.ReadOnly = readOnly;
            btnSave.Visible  = !readOnly;
        }
Пример #32
0
 public override Widget buildTransitions(
     PageRoute route,
     BuildContext context,
     Animation <float> animation,
     Animation <float> secondaryAnimation,
     Widget child)
 {
     return(new _FadeUpwardsPageTransition(
                routeAnimation: animation,
                child: child));
 }
Пример #33
0
            public void ShouldExportAsJson()
            {
                var guid = Guid.NewGuid();
                var pageRoute = new PageRoute
                    {
                        Guid = guid
                    };

                var result = pageRoute.ToJson();
                var key = string.Format( "\"Guid\": \"{0}\"", guid );
                Assert.Greater( result.IndexOf( key ), -1, string.Format( "'{0}' was not found in '{1}'.", key, result ) );
            }
Пример #34
0
        public void ExportJson()
        {
            var guid = Guid.NewGuid();
            var pageRoute = new PageRoute
            {
                Guid = guid
            };

            var result = pageRoute.ToJson();
            var key = string.Format( "\"Guid\": \"{0}\"", guid );
            Assert.NotEqual( result.IndexOf( key ), -1 );
        }
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="itemKey">The item key.</param>
        /// <param name="itemKeyValue">The item key value.</param>
        public void ShowDetail( string itemKey, int itemKeyValue )
        {
            if ( !itemKey.Equals( "pageRouteId" ) )
            {
                return;
            }

            pnlDetails.Visible = true;

            PageRoute pageRoute = null;

            if ( !itemKeyValue.Equals( 0 ) )
            {
                pageRoute = new PageRouteService( new RockContext() ).Get( itemKeyValue );
                lActionTitle.Text = ActionTitle.Edit( PageRoute.FriendlyTypeName ).FormatAsHtmlTitle();
            }
            else
            {
                pageRoute = new PageRoute { Id = 0 };
                lActionTitle.Text = ActionTitle.Add(PageRoute.FriendlyTypeName).FormatAsHtmlTitle();
            }

            hfPageRouteId.Value = pageRoute.Id.ToString();
            ppPage.SetValue( pageRoute.Page );
            tbRoute.Text = pageRoute.Route;

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if ( !IsUserAuthorized( Authorization.EDIT ) )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( PageRoute.FriendlyTypeName );
            }

            if ( pageRoute.IsSystem )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( PageRoute.FriendlyTypeName );
            }

            if ( readOnly )
            {
                lActionTitle.Text = ActionTitle.View( PageRoute.FriendlyTypeName ).FormatAsHtmlTitle();
                btnCancel.Text = "Close";
            }

            ppPage.Enabled = !readOnly;
            tbRoute.ReadOnly = readOnly;
            btnSave.Visible = !readOnly;
        }
        public void RedirectsToLoginReturnPageInTempData_WhenLoginSucceeds()
        {
            _session.SetupGet(it => it.IsAuthenticated).Returns(false);
            _authService.Setup(it => it.Authenticate(_username, _password)).Returns(LoginAttemptResult.Success(_createdAccount));
            var loginRedirectPage = new PageRoute("LoginRedirectPage");

            var controller = new AuthenticationController(_mockSiteMap, _session.Object, _authService.Object);
            new AuthenticationTempData(controller.TempData).LoginReturnPage.Store(loginRedirectPage);

            ActionResult actionResult = controller.Login(_username.ToString(), _password.ToString());

            AssertRedirectedTo(actionResult, loginRedirectPage);
        }
Пример #37
0
            public void ShouldCopyPropertiesToEntity()
            {
                var obj = new PageRoute
                    {
                        Route = "/some/path",
                        IsSystem = true
                    };

                var json = obj.ToJson();
                var pageRoute = PageRoute.FromJson( json );
                Assert.AreEqual( obj.Route, pageRoute.Route );
                Assert.AreEqual( obj.IsSystem, pageRoute.IsSystem );
            }
Пример #38
0
        public void ImportJson()
        {
            var obj = new PageRoute
            {
                Route = "/some/path",
                IsSystem = true
            };

            var json = obj.ToJson();
            var pageRoute = PageRoute.FromJson( json );
            Assert.Equal( obj.Route, pageRoute.Route );
            Assert.Equal( obj.IsSystem, pageRoute.IsSystem );
        }
Пример #39
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 ServerValidate event of the cvPageRoute control.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="args">The <see cref="ServerValidateEventArgs"/> instance containing the event data.</param>
        protected void cvPageRoute_ServerValidate( object source, ServerValidateEventArgs args )
        {
            var errorMessages = new List<string>();

            foreach ( string route in tbPageRoute.Text.SplitDelimitedValues() )
            {
                var pageRoute = new PageRoute();
                pageRoute.Route = route.TrimStart( new char[] { '/' } );
                pageRoute.Guid = Guid.NewGuid();
                if ( !pageRoute.IsValid )
                {
                    errorMessages.Add( string.Format(
                        "The '{0}' route is invalid: {1}",
                        route,
                        pageRoute.ValidationResults.Select( r => r.ErrorMessage ).ToList().AsDelimited( "; " ) ) );
                }
            }

            cvPageRoute.ErrorMessage = errorMessages.AsDelimited( "<br/>" );

            args.IsValid = !errorMessages.Any();
        }
        /// <summary>
        /// Handles the OnSave event of the masterPage 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 masterPage_OnSave( object sender, EventArgs e )
        {
            Page.Validate( BlockValidationGroup );
            if ( Page.IsValid && _pageId.HasValue )
            {
                var rockContext = new RockContext();
                var pageService = new PageService( rockContext );
                var routeService = new PageRouteService( rockContext );
                var contextService = new PageContextService( rockContext );

                var page = pageService.Get( _pageId.Value );

                // validate/check for removed routes
                var editorRoutes = tbPageRoute.Text.SplitDelimitedValues().Distinct();
                var databasePageRoutes = page.PageRoutes.ToList();
                var deletedRouteIds = new List<int>();
                var addedRoutes = new List<string>();

                if ( editorRoutes.Any() )
                {
                    // validate for any duplicate routes
                    var duplicateRoutes = routeService.Queryable()
                        .Where( r => editorRoutes.Contains( r.Route ) && r.PageId != _pageId )
                        .Select( r => r.Route )
                        .Distinct()
                        .ToList();

                    if ( duplicateRoutes.Any() )
                    {
                        // Duplicate routes
                        nbPageRouteWarning.Title = "Duplicate Route(s)";
                        nbPageRouteWarning.Text = string.Format( "<p>The page route <strong>{0}</strong>, already exists for another page. Please choose a different route name.</p>", duplicateRoutes.AsDelimited( "</strong> and <strong>" ) );
                        nbPageRouteWarning.Dismissable = true;
                        nbPageRouteWarning.Visible = true;
                        CurrentTab = "Advanced Settings";

                        rptProperties.DataSource = _tabs;
                        rptProperties.DataBind();
                        ShowSelectedPane();
                        return;
                    }
                }

                // validate if removed routes can be deleted
                foreach ( var pageRoute in databasePageRoutes )
                {
                    if ( !editorRoutes.Contains( pageRoute.Route ) )
                    {
                        // make sure the route can be deleted
                        string errorMessage;
                        if ( !routeService.CanDelete( pageRoute, out errorMessage ) )
                        {
                            nbPageRouteWarning.Text = string.Format( "The page route <strong>{0}</strong>, cannot be removed. {1}", pageRoute.Route, errorMessage );
                            nbPageRouteWarning.NotificationBoxType = NotificationBoxType.Warning;
                            nbPageRouteWarning.Dismissable = true;
                            nbPageRouteWarning.Visible = true;
                            CurrentTab = "Advanced Settings";

                            rptProperties.DataSource = _tabs;
                            rptProperties.DataBind();
                            ShowSelectedPane();
                            return;
                        }
                    }
                }

                // take care of deleted routes
                foreach ( var pageRoute in databasePageRoutes )
                {
                    if ( !editorRoutes.Contains( pageRoute.Route ) )
                    {
                        // if they removed the Route, remove it from the database
                        page.PageRoutes.Remove( pageRoute );

                        routeService.Delete( pageRoute );
                        deletedRouteIds.Add( pageRoute.Id );
                    }
                }

                // take care of added routes
                foreach ( string route in editorRoutes )
                {
                    // if they added the Route, add it to the database
                    if ( !databasePageRoutes.Any( a => a.Route == route ) )
                    {
                        var pageRoute = new PageRoute();
                        pageRoute.Route = route.TrimStart( new char[] { '/' } );
                        pageRoute.Guid = Guid.NewGuid();
                        page.PageRoutes.Add( pageRoute );
                        addedRoutes.Add( route );
                    }
                }

                int parentPageId = ppParentPage.SelectedValueAsInt() ?? 0;
                if ( page.ParentPageId != parentPageId )
                {
                    if ( page.ParentPageId.HasValue )
                    {
                        PageCache.Flush( page.ParentPageId.Value );
                    }

                    if ( parentPageId != 0 )
                    {
                        PageCache.Flush( parentPageId );
                    }
                }

                page.InternalName = tbPageName.Text;
                page.PageTitle = tbPageTitle.Text;
                page.BrowserTitle = tbBrowserTitle.Text;
                if ( parentPageId != 0 )
                {
                    page.ParentPageId = parentPageId;
                }
                else
                {
                    page.ParentPageId = null;
                }

                page.LayoutId = ddlLayout.SelectedValueAsInt().Value;

                int? orphanedIconFileId = null;

                page.IconCssClass = tbIconCssClass.Text;

                page.PageDisplayTitle = cbPageTitle.Checked;
                page.PageDisplayBreadCrumb = cbPageBreadCrumb.Checked;
                page.PageDisplayIcon = cbPageIcon.Checked;
                page.PageDisplayDescription = cbPageDescription.Checked;

                page.DisplayInNavWhen = ddlMenuWhen.SelectedValue.ConvertToEnumOrNull<DisplayInNavWhen>() ?? DisplayInNavWhen.WhenAllowed;
                page.MenuDisplayDescription = cbMenuDescription.Checked;
                page.MenuDisplayIcon = cbMenuIcon.Checked;
                page.MenuDisplayChildPages = cbMenuChildPages.Checked;

                page.BreadCrumbDisplayName = cbBreadCrumbName.Checked;
                page.BreadCrumbDisplayIcon = cbBreadCrumbIcon.Checked;

                page.RequiresEncryption = cbRequiresEncryption.Checked;
                page.EnableViewState = cbEnableViewState.Checked;
                page.IncludeAdminFooter = cbIncludeAdminFooter.Checked;
                page.OutputCacheDuration = tbCacheDuration.Text.AsIntegerOrNull() ?? 0;
                page.Description = tbDescription.Text;
                page.HeaderContent = ceHeaderContent.Text;

                // update PageContexts
                foreach ( var pageContext in page.PageContexts.ToList() )
                {
                    contextService.Delete( pageContext );
                }

                page.PageContexts.Clear();
                foreach ( var control in phContext.Controls )
                {
                    if ( control is RockTextBox )
                    {
                        var tbContext = control as RockTextBox;
                        if ( !string.IsNullOrWhiteSpace( tbContext.Text ) )
                        {
                            var pageContext = new PageContext();
                            pageContext.Entity = tbContext.ID.Substring( 8 ).Replace( '_', '.' );
                            pageContext.IdParameter = tbContext.Text;
                            page.PageContexts.Add( pageContext );
                        }
                    }
                }

                // save page and it's routes
                if ( page.IsValid )
                {
                    rockContext.SaveChanges();

                    // remove any routes that were deleted
                    foreach (var deletedRouteId in deletedRouteIds )
                    {
                        var existingRoute = RouteTable.Routes.OfType<Route>().FirstOrDefault( a => a.RouteId() == deletedRouteId );
                        if ( existingRoute != null )
                        {
                            RouteTable.Routes.Remove( existingRoute );
                        }
                    }

                    // ensure that there aren't any other extra routes for this page in the RouteTable
                    foreach (var routeTableRoute in RouteTable.Routes.OfType<Route>().Where(a => a.PageId() == page.Id))
                    {
                        if ( !editorRoutes.Any( a => a == routeTableRoute.Url ) )
                        {
                            RouteTable.Routes.Remove( routeTableRoute );
                        }
                    }

                    // Add any routes that were added
                    foreach ( var pageRoute in new PageRouteService( rockContext ).GetByPageId( page.Id ) )
                    {
                        if ( addedRoutes.Contains( pageRoute.Route ) )
                        {
                            RouteTable.Routes.AddPageRoute( pageRoute );
                        }
                    }

                    if ( orphanedIconFileId.HasValue )
                    {
                        BinaryFileService binaryFileService = new BinaryFileService( rockContext );
                        var binaryFile = binaryFileService.Get( orphanedIconFileId.Value );
                        if ( binaryFile != null )
                        {
                            // marked the old images as IsTemporary so they will get cleaned up later
                            binaryFile.IsTemporary = true;
                            rockContext.SaveChanges();
                        }
                    }

                    Rock.Web.Cache.PageCache.Flush( page.Id );

                    string script = "if (typeof window.parent.Rock.controls.modal.close === 'function') window.parent.Rock.controls.modal.close('PAGE_UPDATED');";
                    ScriptManager.RegisterStartupScript( this.Page, this.GetType(), "close-modal", script, true );
                }
            }
        }
Пример #42
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;
            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();
            }
        }
Пример #43
0
 public void ShouldCopyEntity()
 {
     var pageRoute = new PageRoute { Guid = Guid.NewGuid() };
     var result = pageRoute.Clone( false );
     Assert.AreEqual( result.Guid, pageRoute.Guid );
 }
 /// <summary>
 /// Removes the page route.
 /// </summary>
 /// <param name="pageRoute">The page route.</param>
 private static void RemovePageRoute( PageRoute pageRoute )
 {
     var existingRoute = RouteTable.Routes.OfType<Route>().FirstOrDefault( a => a.RouteId() == pageRoute.Id );
     if ( existingRoute != null )
     {
         RouteTable.Routes.Remove( existingRoute );
     }
 }
Пример #45
0
 public void ToJson()
 {
     var pageRoute = new PageRoute { Guid = Guid.NewGuid() };
     dynamic result = pageRoute.ToJson();
     Assert.NotEmpty( result );
 }
Пример #46
0
        /// <summary>
        /// Handles the OnSave event of the masterPage 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 masterPage_OnSave( object sender, EventArgs e )
        {
            Page.Validate( BlockValidationGroup );
            if ( Page.IsValid && _pageId.HasValue )
            {
                var rockContext = new RockContext();
                var pageService = new PageService( rockContext );
                var routeService = new PageRouteService( rockContext );
                var contextService = new PageContextService( rockContext );

                var page = pageService.Get( _pageId.Value );

                int parentPageId = ppParentPage.SelectedValueAsInt() ?? 0;
                if ( page.ParentPageId != parentPageId )
                {
                    if ( page.ParentPageId.HasValue )
                    {
                        PageCache.Flush( page.ParentPageId.Value );
                    }

                    if ( parentPageId != 0 )
                    {
                        PageCache.Flush( parentPageId );
                    }
                }

                page.InternalName = tbPageName.Text;
                page.PageTitle = tbPageTitle.Text;
                page.BrowserTitle = tbBrowserTitle.Text;
                if ( parentPageId != 0 )
                {
                    page.ParentPageId = parentPageId;
                }
                else
                {
                    page.ParentPageId = null;
                }

                page.LayoutId = ddlLayout.SelectedValueAsInt().Value;

                int? orphanedIconFileId = null;

                page.IconCssClass = tbIconCssClass.Text;

                page.PageDisplayTitle = cbPageTitle.Checked;
                page.PageDisplayBreadCrumb = cbPageBreadCrumb.Checked;
                page.PageDisplayIcon = cbPageIcon.Checked;
                page.PageDisplayDescription = cbPageDescription.Checked;

                page.DisplayInNavWhen = (DisplayInNavWhen)Enum.Parse( typeof( DisplayInNavWhen ), ddlMenuWhen.SelectedValue );
                page.MenuDisplayDescription = cbMenuDescription.Checked;
                page.MenuDisplayIcon = cbMenuIcon.Checked;
                page.MenuDisplayChildPages = cbMenuChildPages.Checked;

                page.BreadCrumbDisplayName = cbBreadCrumbName.Checked;
                page.BreadCrumbDisplayIcon = cbBreadCrumbIcon.Checked;

                page.RequiresEncryption = cbRequiresEncryption.Checked;
                page.EnableViewState = cbEnableViewState.Checked;
                page.IncludeAdminFooter = cbIncludeAdminFooter.Checked;
                page.OutputCacheDuration = int.Parse( tbCacheDuration.Text );
                page.Description = tbDescription.Text;
                page.HeaderContent = ceHeaderContent.Text;

                // new or updated route
                foreach ( var pageRoute in page.PageRoutes.ToList() )
                {
                    var existingRoute = RouteTable.Routes.OfType<Route>().FirstOrDefault( a => a.RouteId() == pageRoute.Id );
                    if ( existingRoute != null )
                    {
                        RouteTable.Routes.Remove( existingRoute );
                    }

                    routeService.Delete( pageRoute );
                }

                page.PageRoutes.Clear();

                foreach ( string route in tbPageRoute.Text.SplitDelimitedValues() )
                {
                    var pageRoute = new PageRoute();
                    pageRoute.Route = route.TrimStart( new char[] { '/' } );
                    pageRoute.Guid = Guid.NewGuid();
                    page.PageRoutes.Add( pageRoute );
                }

                foreach ( var pageContext in page.PageContexts.ToList() )
                {
                    contextService.Delete( pageContext );
                }

                page.PageContexts.Clear();
                foreach ( var control in phContext.Controls )
                {
                    if ( control is RockTextBox )
                    {
                        var tbContext = control as RockTextBox;
                        if ( !string.IsNullOrWhiteSpace( tbContext.Text ) )
                        {
                            var pageContext = new PageContext();
                            pageContext.Entity = tbContext.ID.Substring( 8 ).Replace( '_', '.' );
                            pageContext.IdParameter = tbContext.Text;
                            page.PageContexts.Add( pageContext );
                        }
                    }
                }

                if ( page.IsValid )
                {
                    rockContext.SaveChanges();

                    foreach ( var pageRoute in new PageRouteService( rockContext ).GetByPageId( page.Id ) )
                    {
                        RouteTable.Routes.AddPageRoute( pageRoute );
                    }

                    if ( orphanedIconFileId.HasValue )
                    {
                        BinaryFileService binaryFileService = new BinaryFileService( rockContext );
                        var binaryFile = binaryFileService.Get( orphanedIconFileId.Value );
                        if ( binaryFile != null )
                        {
                            // marked the old images as IsTemporary so they will get cleaned up later
                            binaryFile.IsTemporary = true;
                            rockContext.SaveChanges();
                        }
                    }

                    Rock.Web.Cache.PageCache.Flush( page.Id );

                    string script = "if (typeof window.parent.Rock.controls.modal.close === 'function') window.parent.Rock.controls.modal.close('PAGE_UPDATED');";
                    ScriptManager.RegisterStartupScript( this.Page, this.GetType(), "close-modal", script, true );
                }

            }
        }
Пример #47
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;
            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();
        }
Пример #48
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;
            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();
            }
        }
Пример #49
0
 public void ShallowClone()
 {
     var pageRoute = new PageRoute { Guid = Guid.NewGuid() };
     var result = pageRoute.Clone( false );
     Assert.Equal( result.Guid, pageRoute.Guid );
 }