private async Task <PageVersion> CreateDraftIfRequiredAsync(int pageId, PageVersion draft)
        {
            if (draft != null)
            {
                return(draft);
            }

            var command = new AddPageDraftVersionCommand();

            command.PageId = pageId;
            await _commandExecutor.ExecuteAsync(command);

            return(await GetDraftVersion(pageId).SingleOrDefaultAsync());
        }
        public async Task <IHttpActionResult> PatchDraft(int pageId, Delta <UpdatePageDraftVersionCommand> delta)
        {
            // Custom patching because we may need to create a draft version first
            var command = await _queryExecutor.GetByIdAsync <UpdatePageDraftVersionCommand>(pageId);

            if (command == null)
            {
                var createDraftCommand = new AddPageDraftVersionCommand();
                createDraftCommand.PageId = pageId;
                await _commandExecutor.ExecuteAsync(createDraftCommand);

                command = await _queryExecutor.GetByIdAsync <UpdatePageDraftVersionCommand>(pageId);
            }

            delta.Patch(command);

            return(await _apiResponseHelper.RunCommandAsync(this, command));
        }
예제 #3
0
        /// <summary>
        /// Adds a draft version to the specified page and returns the version id.
        /// </summary>
        /// <param name="pageId">Id of the page to add a draft to.</param>
        /// <returns>The PageVersionId of the newly created version.</returns>
        public async Task <int> AddDraftAsync(int pageId)
        {
            var command = new AddPageDraftVersionCommand()
            {
                PageId = pageId
            };

            using var scope = _serviceProvider.CreateScope();
            var contentRepository = scope
                                    .ServiceProvider
                                    .GetRequiredService <IAdvancedContentRepository>()
                                    .WithElevatedPermissions();

            return(await contentRepository
                   .Pages()
                   .Versions()
                   .AddDraftAsync(command));
        }
        public async Task <JsonResult> PatchDraft(int pageId, [FromBody] IDelta <UpdatePageDraftVersionCommand> delta)
        {
            // Custom patching because we may need to create a draft version first
            var query   = new GetPatchableCommandByIdQuery <UpdatePageDraftVersionCommand>(pageId);
            var command = await _domainRepository.ExecuteQueryAsync(query);

            if (command == null)
            {
                var createDraftCommand = new AddPageDraftVersionCommand();
                createDraftCommand.PageId = pageId;
                await _domainRepository.ExecuteCommandAsync(createDraftCommand);

                command = await _domainRepository.ExecuteQueryAsync(query);
            }

            delta.Patch(command);

            return(await _apiResponseHelper.RunCommandAsync(command));
        }
예제 #5
0
        public async Task <int> AddDraftAsync(AddPageDraftVersionCommand command)
        {
            await ExtendableContentRepository.ExecuteCommandAsync(command);

            return(command.OutputPageVersionId);
        }
 public async Task <IHttpActionResult> Post(AddPageDraftVersionCommand command)
 {
     return(await _apiResponseHelper.RunCommandAsync(this, command));
 }
예제 #7
0
        public async Task ExecuteAsync(Controller controller, PageActionRoutingState state)
        {
            var pageRoutingInfo = state.PageRoutingInfo;

            if (pageRoutingInfo == null)
            {
                return;
            }

            // If there's no draft version and we're in edit mode for 'Pages' then
            // create one and re-run the query
            var publishStatus = state.VisualEditorState.GetPublishStatusQuery();

            if (!state.InputParameters.IsEditingCustomEntity &&
                publishStatus != PublishStatusQuery.Published &&
                publishStatus != PublishStatusQuery.SpecificVersion &&
                state.IsCofoundryAdminUser)
            {
                var versionRouting = pageRoutingInfo.PageRoute.Versions.GetVersionRouting(publishStatus);
                if (versionRouting == null)
                {
                    var command = new AddPageDraftVersionCommand()
                    {
                        PageId = pageRoutingInfo.PageRoute.PageId
                    };
                    await _commandExecutor.ExecuteAsync(command, state.CofoundryAdminExecutionContext);

                    var pageQuery = GetPageRoutingInfoQuery(state);
                    pageRoutingInfo = await _queryExecutor.ExecuteAsync(pageQuery);
                }
            }

            if (pageRoutingInfo.CustomEntityRoute != null &&
                pageRoutingInfo.PageRoute.PageType == PageType.CustomEntityDetails)
            {
                var correctUrl = pageRoutingInfo.CustomEntityRouteRule.MakeUrl(pageRoutingInfo.PageRoute, pageRoutingInfo.CustomEntityRoute);
                if (!state.InputParameters.Path.Equals(correctUrl.TrimStart('/'), StringComparison.OrdinalIgnoreCase))
                {
                    Debug.WriteLine("Incorrect Custom Entity Url detected, redirecting from " + state.InputParameters.Path + " to " + correctUrl);
                    state.Result = new RedirectResult(correctUrl, true);
                }
                else if (state.InputParameters.IsEditingCustomEntity &&
                         publishStatus != PublishStatusQuery.Published &&
                         publishStatus != PublishStatusQuery.SpecificVersion &&
                         state.IsCofoundryAdminUser)
                {
                    var versionRouting = pageRoutingInfo.CustomEntityRoute.Versions.GetVersionRouting(publishStatus);
                    if (versionRouting == null)
                    {
                        // if no draft version for route, add one.
                        var addDraftVersionCommand = new AddCustomEntityDraftVersionCommand()
                        {
                            CustomEntityId = pageRoutingInfo.CustomEntityRoute.CustomEntityId
                        };
                        await _commandExecutor.ExecuteAsync(addDraftVersionCommand, state.CofoundryAdminExecutionContext);

                        var pageQuery = GetPageRoutingInfoQuery(state);
                        pageRoutingInfo = await _queryExecutor.ExecuteAsync(pageQuery);
                    }
                }
            }

            state.PageRoutingInfo = pageRoutingInfo;
        }
 public Task <JsonResult> Post([FromBody] AddPageDraftVersionCommand command)
 {
     return(_apiResponseHelper.RunCommandAsync(command));
 }