示例#1
0
        public void Save(CmsPage cmsPage, PageRelativePosition pageRelativePosition)
        {
            var position = new SitemapRelativePosition
            {
            };

            if (pageRelativePosition.ParentPageId != null)
            {
                var parentNodeSearch = $@"{nameof(CmsPageLocationNode.PageId)} == {{{pageRelativePosition.ParentPageId}}}";

                var parentNode = Orm.FindUnversionedContent <CmsPageLocationNode>(SqlFilter.FromEntityFilter(parentNodeSearch, typeof(CmsPageLocationNode))).Result
                                 .SingleOrDefault();

                position.ParentSitemapNodeId = parentNode?.NodeId;
            }


            if (pageRelativePosition.BeforePageId != null)
            {
                var beforeNodeSearch = $@"{nameof(CmsPageLocationNode.PageId)} == {{{pageRelativePosition.BeforePageId}}}";
                var beforeNode       = Orm.FindUnversionedContent <CmsPageLocationNode>(SqlFilter.FromEntityFilter(beforeNodeSearch, typeof(CmsPageLocationNode))).Result
                                       .SingleOrDefault();

                position.BeforeSitemapNodeId = beforeNode?.NodeId;
            }


            Save(cmsPage, position);
        }
示例#2
0
        public void Move(CmsPage page, SitemapRelativePosition newSitemapRelativePosition)
        {
            var sqlFilter = SqlFilter.FromEntityFilter($@"{nameof(CmsPageLocationNode.PageId)} == {{{page.ContentId}}}", typeof(CmsPageLocationNode));

            var newPageLocation = Orm.FindUnversionedContent <CmsPageLocationNode>(sqlFilter).Result.SingleOrDefault();

            if (newPageLocation == null)
            {
                newPageLocation = new CmsPageLocationNode();
            }
            else
            {
                AppendToRouteHistory(page);
            }

            newPageLocation.ContentId = Guid.NewGuid();
            newPageLocation.PageId    = page.ContentId;
            newPageLocation.SiteId    = page.SiteId;

            if (newSitemapRelativePosition.ParentSitemapNodeId == null ||
                newSitemapRelativePosition.ParentSitemapNodeId == Guid.Empty)
            {
                newSitemapRelativePosition.ParentSitemapNodeId = page.SiteId;
            }

            newPageLocation.ParentNodeId = newSitemapRelativePosition.ParentSitemapNodeId.Value;


            var expressionText    = $"SiteId == {{{page.SiteId}}} && ParentNodeId == {{{newSitemapRelativePosition.ParentSitemapNodeId.Value}}}";
            var booleanExpression = By.Condition(expressionText);
            var cmsPageSql        = SqlTranslator.Build(booleanExpression, typeof(CmsPageLocationNode));

            var sitemapNodesToUpdate = Orm.FindUnversionedContent <CmsPageLocationNode>(cmsPageSql).Result;
            var collection           = sitemapNodesToUpdate.ToList();

            var insertAt = 0;

            if (null != newSitemapRelativePosition.BeforeSitemapNodeId)
            {
                var beforeNode = collection.Single(x => newSitemapRelativePosition.BeforeSitemapNodeId == x.NodeId);
                insertAt = collection.IndexOf(beforeNode);
            }
            collection.Insert(insertAt, newPageLocation);

            for (int i = 0; i < collection.Count; i++)
            {
                collection[i].Order = i;
                Orm.Save(collection[i]);
            }

            DomainEvents.Raise(new SiteStructureChanged());
        }
示例#3
0
        protected override void SaveImpl(VersionedContentEntity vce)
        {
            CmsPage cmsPage = (CmsPage)vce;

            SitemapRelativePosition sitemapRelativePosition;

            if (cmsPage.IsNew)
            {
                sitemapRelativePosition = SitemapRelativePosition.Root;
            }
            else
            {
                var existingLocationSearch = $@"{nameof(CmsPageLocationNode.PageId)} == {{{cmsPage.ContentId}}}";
                var sqlFilter = SqlTranslator.Build(By.Condition(existingLocationSearch), typeof(CmsPageLocationNode));

                var node             = Orm.FindUnversionedContent <CmsPageLocationNode>(sqlFilter).Result.Single();
                var siblingSearch    = $@"{nameof(CmsPageLocationNode.SiteId)} == {{{cmsPage.SiteId}}} && {nameof(CmsPageLocationNode.ParentNodeId)} == {{{node.ParentNodeId}}}";
                var siblingSqlFilter = SqlTranslator.Build(By.Condition(siblingSearch), typeof(CmsPageLocationNode));

                var siblingNodes  = Orm.FindUnversionedContent <CmsPageLocationNode>(siblingSqlFilter).Result;
                var newBeforeNode = siblingNodes.Where(x => x.Order > node.Order).OrderBy(x => x.Order).FirstOrDefault();


                sitemapRelativePosition = new SitemapRelativePosition
                {
                    ParentSitemapNodeId = node.ParentNodeId,
                    BeforeSitemapNodeId = newBeforeNode?.NodeId,
                };
            }


            Save(cmsPage, sitemapRelativePosition);


            //todo: save this stuff.
            //page.Routes.Where(x => x.Slug == newDefaultSlug)

            //_dbAdapter.Save();
            //SlugGenerator.Generate(page.Name)
            //new RouteRepository().GetAllRoutes().
            //new Page().Name
            //page.Name
        }
示例#4
0
        private void AssertSlugIsNotTaken(CmsPage cmsPage, SitemapRelativePosition newSitemapRelativePosition)
        {
            ISiteStructureNode parentNode;

            if (Guid.Empty == newSitemapRelativePosition.ParentSitemapNodeId || cmsPage.SiteId == newSitemapRelativePosition.ParentSitemapNodeId)
            {
                parentNode = new SiteStructure(cmsPage.SiteId);
            }
            else
            {
                var findParentCondition = By.Condition($@"{nameof(CmsPageLocationNode.ContentId)} == {{{newSitemapRelativePosition.ParentSitemapNodeId}}}");
                var sqlCondition        = SqlTranslator.Build(findParentCondition, typeof(CmsPage));

                var parentNodes = Orm.FindUnversionedContent <CmsPageLocationNode>(sqlCondition).Result;
                if (!parentNodes.Any())
                {
                    throw new Exception("Could not find a structual node for: '" + findParentCondition + "'");
                }

                parentNode = parentNodes.Single();
            }

            //var siblingsCondition = $@"{nameof(CmsPageLocationNode.PageId)} == {{{cmsPage.ContentEnvironment}}} && {nameof(CmsPageLocationNode.ParentNodeId)} == {{{parentNode.NodeId}}}";
            //var sqlFilter =SqlFilter.FromEntityFilter(siblingsCondition, typeof(CmsPageLocationNode));
            //var siblings = Orm.FindUnversionedContent<CmsPageLocationNode>(sqlFilter).Result.ToList();


            //foreach (var sibling in siblings)
            //{
            //    this.FindContentVersions()
            //}



            //var dupSlugs = GetAllPages()
            //    .Where(x => x.ParentPageId == cmsPage.ParentPageId && x.Id != cmsPage.Id)
            //    .SelectMany(x => x.Routes)
            //    .Where(x => x.Priority == (int) RoutePriority.Primary);

            //if (dupSlugs.Any())
            //    throw new DuplicateSlugException();
        }
示例#5
0
        public IEnumerable <HistoricalRoute> GetHistoricalPageLocations(Site site)
        {
            var sqlFilter = SqlFilter.FromEntityFilter("SiteId == {" + site.ContentId + "}", typeof(HistoricalRoute));

            return(Orm.FindUnversionedContent <HistoricalRoute>(sqlFilter).Result);
        }