public PageContentChildRegionViewModel(ContentRegion contentRegion) { if (contentRegion != null) { RegionId = contentRegion.Region.Id; RegionIdentifier = contentRegion.Region.RegionIdentifier; } }
public int GetLastDynamicRegionNumber(Guid pageId) { ContentRegion crAlias = null; Region regionAlias = null; Root.Models.Content contentAlias = null; Root.Models.Content hAlias = null; PageContent pcAlias = null; // Load all original contents var originalFuture = repository .AsQueryOver(() => crAlias) .Inner.JoinAlias(() => crAlias.Region, () => regionAlias) .Inner.JoinAlias(() => crAlias.Content, () => contentAlias) .Inner.JoinAlias(() => contentAlias.PageContents, () => pcAlias) .Where(() => pcAlias.Page.Id == pageId) .And(() => contentAlias.GetType() == typeof(HtmlContent)) .And(() => contentAlias.Status == ContentStatus.Draft || contentAlias.Status == ContentStatus.Published) .And(() => !crAlias.IsDeleted && !contentAlias.IsDeleted && !pcAlias.IsDeleted) .SelectList(list => list.SelectGroup(() => regionAlias.RegionIdentifier)) .Future <string>(); // Load all draft contents var draftFuture = repository .AsQueryOver(() => crAlias) .Inner.JoinAlias(() => crAlias.Region, () => regionAlias) .Inner.JoinAlias(() => crAlias.Content, () => hAlias) .Inner.JoinAlias(() => hAlias.Original, () => contentAlias) .Inner.JoinAlias(() => contentAlias.PageContents, () => pcAlias) .Where(() => pcAlias.Page.Id == pageId) .And(() => contentAlias.GetType() == typeof(HtmlContent)) .And(() => hAlias.Status == ContentStatus.Draft && contentAlias.Status == ContentStatus.Published) .And(() => !crAlias.IsDeleted && !contentAlias.IsDeleted && !pcAlias.IsDeleted && !hAlias.IsDeleted) .SelectList(list => list.SelectGroup(() => regionAlias.RegionIdentifier)) .Future <string>(); var regionIdentifiers = draftFuture.ToList().Concat(originalFuture.ToList()).Distinct(); return(RegionHelper.GetLastDynamicRegionNumber(regionIdentifiers)); }
private IList <ChildContent> GetChildContents(Guid[] ids, bool canManageContent) { ChildContent ccAlias = null; ChildContentOption ccOptionAlias = null; Models.Content childAlias = null; ContentOption cOptionAlias = null; ContentRegion cRegionAlias = null; Region regionAlias = null; ChildContent ccAlias1 = null; Models.Content ccChildAlias = null; Models.Content historyAlias = null; ChildContent historyCcAlias = null; Models.Content historyChildAlias = null; var query = repository .AsQueryOver(() => ccAlias) .Where(Restrictions.In(NHibernate.Criterion.Projections.Property(() => ccAlias.Parent.Id), ids)) .And(() => !ccAlias.IsDeleted) .Inner.JoinAlias(() => ccAlias.Child, () => childAlias) .Where(() => !childAlias.IsDeleted) .Left.JoinAlias(() => childAlias.ContentOptions, () => cOptionAlias) .Left.JoinAlias(() => ccAlias.Options, () => ccOptionAlias) .Left.JoinAlias(() => childAlias.ContentRegions, () => cRegionAlias) .Left.JoinAlias(() => cRegionAlias.Region, () => regionAlias) .Left.JoinAlias(() => childAlias.ChildContents, () => ccAlias1) .Left.JoinAlias(() => ccAlias1.Child, () => ccChildAlias); if (canManageContent) { query = query .Left.JoinAlias(() => childAlias.History, () => historyAlias) .Left.JoinAlias(() => historyAlias.ChildContents, () => historyCcAlias) .Left.JoinAlias(() => historyCcAlias.Child, () => historyChildAlias); } return(query.List <ChildContent>()); }
public void Should_CRUD_BlogPost_WithMasterPage_Successfully() { // Attach to events Events.BlogEvents.Instance.BlogCreated += Instance_EntityCreated; Events.BlogEvents.Instance.BlogUpdated += Instance_EntityUpdated; Events.BlogEvents.Instance.BlogDeleted += Instance_EntityDeleted; RunApiActionInTransaction( (api, session) => { isMarkdown = false; isHtmlSet = true; isNullUrl = false; masterPage = TestDataProvider.CreateNewPage(); masterPage.IsMasterPage = true; layout = null; var htmlContent = TestDataProvider.CreateNewHtmlContent(100); region = TestDataProvider.CreateNewRegion(); var contentRegion = new ContentRegion { Content = htmlContent, Region = region }; htmlContent.ContentRegions = new[] { contentRegion }; var pageContent = new PageContent { Page = masterPage, Content = htmlContent, Region = region }; session.SaveOrUpdate(region); session.SaveOrUpdate(htmlContent); session.SaveOrUpdate(masterPage); session.SaveOrUpdate(pageContent); Run(session, api.Blog.BlogPost.Properties.Post, api.Blog.BlogPost.Properties.Get, api.Blog.BlogPost.Properties.Put, api.Blog.BlogPost.Properties.Delete); }); // Detach from events Events.BlogEvents.Instance.BlogCreated -= Instance_EntityCreated; Events.BlogEvents.Instance.BlogUpdated -= Instance_EntityUpdated; Events.BlogEvents.Instance.BlogDeleted -= Instance_EntityDeleted; }
private void CheckIfContentHasDeletingWidgetsWithDynamicRegions(Widget widget, string targetHtml) { var sourceHtml = ((IDynamicContentContainer)widget).Html; var sourceWidgets = PageContentRenderHelper.ParseWidgetsFromHtml(sourceHtml); var targetWidgets = PageContentRenderHelper.ParseWidgetsFromHtml(targetHtml); // Get ids of child widgets, which are being removed from the content var removingWidgetIds = sourceWidgets .Where(sw => targetWidgets.All(tw => tw.WidgetId != sw.WidgetId)) .Select(sw => sw.WidgetId) .Distinct() .ToArray(); if (removingWidgetIds.Any()) { var childContents = childContentService.RetrieveChildrenContentsRecursively(true, removingWidgetIds); var childContentIds = childContents.Select(cc => cc.Child.Id).Distinct().ToList(); PageContent pcAlias = null; ContentRegion contentRegionAlias = null; var subQuery = QueryOver.Of(() => contentRegionAlias) .Where(() => !contentRegionAlias.IsDeleted) .And(Restrictions.In(Projections.Property(() => contentRegionAlias.Content.Id), childContentIds)) .And(() => contentRegionAlias.Region == pcAlias.Region) .Select(cr => cr.Id); var areAnyContentUsages = repository.AsQueryOver(() => pcAlias) .WithSubquery.WhereExists(subQuery) .And(() => !pcAlias.IsDeleted) .RowCount() > 0; if (areAnyContentUsages) { var message = PagesGlobalization.SaveWidget_ContentHasChildrenWidgetWithDynamicContents_ConfirmationMessage; var logMessage = string.Format("User is trying to remove child widget which has children with dynamic regions and assigned contents. Confirmation is required."); throw new ConfirmationRequestException(() => message, logMessage); } } }
private void CollectDynamicRegions(string html, Models.Content content, IList <ContentRegion> contentRegions) { var regionIdentifiers = GetRegionIds(html); if (regionIdentifiers.Length > 0) { var regionIdentifiersLower = regionIdentifiers.Select(s => s.ToLowerInvariant()).ToArray(); var existingRegions = repository .AsQueryable <Region>() .Where(r => regionIdentifiersLower.Contains(r.RegionIdentifier.ToLowerInvariant())) .ToArray(); foreach (var regionId in regionIdentifiers.Where(s => contentRegions.All(region => region.Region.RegionIdentifier != s))) { var region = existingRegions.FirstOrDefault(r => r.RegionIdentifier.ToLowerInvariant() == regionId.ToLowerInvariant()); if (region == null) { region = contentRegions .Where(cr => cr.Region.RegionIdentifier.ToLowerInvariant() == regionId.ToLowerInvariant()) .Select(cr => cr.Region).FirstOrDefault(); if (region == null) { region = new Region { RegionIdentifier = regionId }; } } var contentRegion = new ContentRegion { Region = region, Content = content }; contentRegions.Add(contentRegion); } } }
public void CollectDynamicRegions(string html, Models.Content content, IList<ContentRegion> contentRegions) { var regionIdentifiers = GetRegionIds(html); if (regionIdentifiers.Length > 0) { var existingRegions = repository .AsQueryable<Region>() .Where(r => regionIdentifiers.Contains(r.RegionIdentifier)) .ToArray(); foreach (var regionId in regionIdentifiers.Where(s => contentRegions.All(region => region.Region.RegionIdentifier != s))) { var region = existingRegions.FirstOrDefault(r => r.RegionIdentifier == regionId); if (region == null) { region = contentRegions .Where(cr => cr.Region.RegionIdentifier == regionId) .Select(cr => cr.Region).FirstOrDefault(); if (region == null) { region = new Region { RegionIdentifier = regionId }; } } var contentRegion = new ContentRegion { Region = region, Content = content }; contentRegions.Add(contentRegion); } } }