public static void AlterPartDefinition(this IContentDefinitionManager manager, string name, Action <ContentPartDefinitionBuilder> alteration)
        {
            var partDefinition = manager.LoadPartDefinition(name) ?? new ContentPartDefinition(name);
            var builder        = new ContentPartDefinitionBuilder(partDefinition);

            alteration(builder);
            manager.StorePartDefinition(builder.Build());
        }
        public static async Task AlterPartDefinitionAsync(this IContentDefinitionManager manager, string name, Func <ContentPartDefinitionBuilder, Task> alterationAsync)
        {
            var partDefinition = manager.LoadPartDefinition(name) ?? new ContentPartDefinition(name);
            var builder        = new ContentPartDefinitionBuilder(partDefinition);

            await alterationAsync(builder);

            manager.StorePartDefinition(builder.Build());
        }
Пример #3
0
        public async Task <ActionResult> EditPOST(string id, EditTypeViewModel viewModel)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes))
            {
                return(Forbid());
            }

            var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition(id);

            if (contentTypeDefinition == null)
            {
                return(NotFound());
            }



            viewModel.Settings       = contentTypeDefinition.Settings;
            viewModel.TypeDefinition = contentTypeDefinition;
            viewModel.DisplayName    = contentTypeDefinition.DisplayName;
            viewModel.Editor         = await _contentDefinitionDisplayManager.UpdateTypeEditorAsync(contentTypeDefinition, _updateModelAccessor.ModelUpdater);

            if (!ModelState.IsValid)
            {
                _documentStore.Cancel();

                return(View(viewModel));
            }
            else
            {
                var ownedPartDefinition = _contentDefinitionManager.LoadPartDefinition(contentTypeDefinition.Name);
                if (ownedPartDefinition != null && viewModel.OrderedFieldNames != null)
                {
                    _contentDefinitionService.AlterPartFieldsOrder(ownedPartDefinition, viewModel.OrderedFieldNames);
                }
                _contentDefinitionService.AlterTypePartsOrder(contentTypeDefinition, viewModel.OrderedPartNames);
                _notifier.Success(H["\"{0}\" settings have been saved.", contentTypeDefinition.Name]);
            }

            return(RedirectToAction("Edit", new { id }));
        }
        public EditPartViewModel LoadPart(string name)
        {
            var contentPartDefinition = _contentDefinitionManager.LoadPartDefinition(name);

            if (contentPartDefinition == null)
            {
                var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition(name);

                if (contentTypeDefinition == null)
                {
                    return(null);
                }

                contentPartDefinition = new ContentPartDefinition(name);
            }

            var viewModel = new EditPartViewModel(contentPartDefinition);

            return(viewModel);
        }