/// <summary>
        /// Adds a block of the type associated with the specified data model
        /// to a page version.
        /// </summary>
        /// <param name="pageVersionId">A page version to add the block to.</param>
        /// <param name="pageTemplateRegionId">
        /// The region of the template to add the block to. The block is appended to the end of the region.
        /// </param>
        /// <param name="dataModel">The data to add to the block type.</param>
        /// <param name="configration">
        /// Optional additional configuration action to run before the
        /// command is executed.
        /// </param>
        /// <returns>The PageVersionBlockId of the newly created block.</returns>
        public async Task <int> AddBlockAsync <TDataModel>(
            int pageVersionId,
            int pageTemplateRegionId,
            TDataModel dataModel,
            Action <AddPageVersionBlockCommand, PageBlockTypeSummary> configuration = null
            )
            where TDataModel : IPageBlockTypeDataModel
        {
            using var scope = _serviceProvider.CreateScope();
            var contentRepository = scope
                                    .ServiceProvider
                                    .GetRequiredService <IAdvancedContentRepository>()
                                    .WithElevatedPermissions();

            var allBlocks = await contentRepository
                            .PageBlockTypes()
                            .GetAll()
                            .AsSummaries()
                            .ExecuteAsync();

            var fileName  = dataModel.GetType().Name.Replace("DataModel", string.Empty);
            var blockType = allBlocks.SingleOrDefault(b => b.FileName == fileName);
            var command   = new AddPageVersionBlockCommand()
            {
                DataModel            = dataModel,
                PageBlockTypeId      = blockType.PageBlockTypeId,
                PageTemplateRegionId = pageTemplateRegionId,
                PageVersionId        = pageVersionId
            };

            if (configuration != null)
            {
                configuration(command, blockType);
            }

            return(await contentRepository
                   .Pages()
                   .Versions()
                   .Regions()
                   .Blocks()
                   .AddAsync(command));
        }
        public async Task <int> AddAsync(AddPageVersionBlockCommand command)
        {
            await ExtendableContentRepository.ExecuteCommandAsync(command);

            return(command.OutputPageBlockId);
        }
 public Task <JsonResult> Post([ModelBinder(BinderType = typeof(PageVersionBlockDataModelCommandModelBinder))] AddPageVersionBlockCommand command)
 {
     return(_apiResponseHelper.RunCommandAsync(command));
 }
 public async Task <IActionResult> Post([ModelBinder(BinderType = typeof(PageVersionBlockDataModelCommandModelBinder))] AddPageVersionBlockCommand command)
 {
     return(await _apiResponseHelper.RunCommandAsync(this, command));
 }