Example #1
0
        public async Task <ActionResult> EditPOST(string id, EditTypeViewModel viewModel)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes))
            {
                return(Unauthorized());
            }

            var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(id);

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

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

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

                HackModelState(nameof(EditTypeViewModel.OrderedFieldNames));
                HackModelState(nameof(EditTypeViewModel.OrderedPartNames));

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

            return(RedirectToAction("Edit", new { id }));
        }