/// <inheritdoc />
        public ApiResponse <ContentModelData> GetTemplate(Guid templateId, CancellationToken cancellationToken)
        {
            var template         = _futureNhsContentService.GetPublishedContent(templateId, cancellationToken);
            var contentModelData = _futureNhsContentService.ResolvePublishedContent(template);

            return(new ApiResponse <ContentModelData>().Success(contentModelData, "Template retrieved successfully."));
        }
示例#2
0
        /// <inheritdoc />
        public IEnumerable <string> GetBlockPlaceholderValues(Guid blockId, string propertyGroupAlias, CancellationToken cancellationToken)
        {
            var block           = _futureNhsContentService.GetPublishedContent(blockId, cancellationToken);
            var contentType     = _contentTypeService.Get(block.ContentType.Alias);
            var propertyGroup   = contentType.PropertyGroups.FirstOrDefault(x => x.Alias == propertyGroupAlias);
            var groupProperties = propertyGroup?.PropertyTypes.Select(x => x.Alias);

            return((from property in block.Properties.Where(x => groupProperties != null && groupProperties.Contains(x.Alias))
                    let converter = _converters.FirstOrDefault(x => x.EditorAlias.Equals(property.PropertyType.EditorAlias))
                                    where converter != null
                                    select property.GetValue().ToString()).ToList());
        }
        /// <inheritdoc />
        public ApiResponse <string> PublishContentAndAssociatedContent(Guid contentId, CancellationToken cancellationToken)
        {
            var draftContent     = _futureNhsContentService.GetDraftContent(contentId, cancellationToken);
            var publishedContent = _futureNhsContentService.GetPublishedContent(contentId, cancellationToken);

            var resolvedDraftContent     = _futureNhsContentService.ResolveDraftContent(draftContent);
            var resolvedPublishedContent = _futureNhsContentService.ResolvePublishedContent(publishedContent);

            // Get context content blocks
            var draftBlocks     = publishedContent.Children.Select(x => _futureNhsContentService.ResolveDraftContent(_futureNhsContentService.GetDraftContent(x.Key, cancellationToken)));
            var publishedBlocks = publishedContent.Children.Select(x => _futureNhsContentService.ResolvePublishedContent(_futureNhsContentService.GetPublishedContent(x.Key, cancellationToken)));

            // Find the difference between published and draft contents list of blocks
            var blocksToRemove = _futureNhsContentService.CompareContentModelLists(publishedBlocks, draftBlocks);

            // Delete blocks.
            _futureNhsContentService.DeleteContent(blocksToRemove, cancellationToken);

            // Publish draft blocks
            foreach (var block in draftBlocks)
            {
                var draftBlock = _futureNhsContentService.GetDraftContent(block.Item.Id, cancellationToken);
                _futureNhsContentService.PublishContent(draftBlock, cancellationToken);
            }

            // Publish draft blocks child blocks
            var draftBlocksChildBlocks = _futureNhsBlockService.GetAllDescendentBlockIds(draftBlocks, cancellationToken);

            foreach (var block in draftBlocksChildBlocks)
            {
                var draftBlock = _futureNhsContentService.GetDraftContent(block.Item.Id, cancellationToken);
                _futureNhsContentService.PublishContent(draftBlock, cancellationToken);
            }

            // Publish main content
            _futureNhsContentService.PublishContent(draftContent, cancellationToken);

            return(new ApiResponse <string>().Success(contentId.ToString(), "Content and associated content successfully published."));
        }
        /// <inheritdoc />
        public ApiResponse <IEnumerable <SitemapGroupItemModel> > GetSitemapGroupItems(Guid pageId, CancellationToken cancellationToken)
        {
            // Get published page
            var page = _futureNhsContentService.GetPublishedContent(pageId, cancellationToken);

            // if page is root node, generate tree from this page.
            if (_futureNhsSiteMapService.IsRoot(page))
            {
                return(new ApiResponse <IEnumerable <SitemapGroupItemModel> >().Success(PopulateGroupSiteMapItemViewModel(page), "Success."));
            }

            // else, find root and generate from that page.
            return(new ApiResponse <IEnumerable <SitemapGroupItemModel> >().Success(PopulateGroupSiteMapItemViewModel(_futureNhsSiteMapService.GetRoot(page)), "Success."));
        }
示例#5
0
        /// <inheritdoc />
        public ApiResponse <IEnumerable <ContentModelData> > GetAllBlocks(CancellationToken cancellationToken)
        {
            var blocksFolderGuid = _config.GetValue <Guid>("AppKeys:Folders:PlaceholderBlocks");

            if (blocksFolderGuid == Guid.Empty)
            {
                throw new NullReferenceException($"Placeholder blocks folder guid cannot be null.");
            }
            ;

            var placeholderBlocksFolder = _futureNhsContentService.GetPublishedContent(blocksFolderGuid, cancellationToken);

            var contentModelList = new List <ContentModelData>();

            if (placeholderBlocksFolder.Children is not null && placeholderBlocksFolder.Children.Any())
            {
                foreach (var block in placeholderBlocksFolder.Children)
                {
                    contentModelList.Add(_futureNhsContentService.ResolvePublishedContent(block));
                }
            }

            return(new ApiResponse <IEnumerable <ContentModelData> >().Success(contentModelList, "Success."));
        }