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); }
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()); }
public IEnumerable <HistoricalRoute> GetHistoricalPageLocations(Site site) { var sqlFilter = SqlFilter.FromEntityFilter("SiteId == {" + site.ContentId + "}", typeof(HistoricalRoute)); return(Orm.FindUnversionedContent <HistoricalRoute>(sqlFilter).Result); }