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

            var partViewModel = _contentDefinitionService.GetPart(id);

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

            var field = partViewModel.PartDefinition.Fields.FirstOrDefault(x => x.Name == name);

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

            _contentDefinitionService.RemoveFieldFromPart(name, partViewModel.Name);

            _notifier.Success(T["The \"{0}\" field has been removed.", field.DisplayName()]);

            if (_contentDefinitionService.GetType(id) != null)
            {
                return(RedirectToAction("Edit", new { id }));
            }

            return(RedirectToAction("EditPart", new { id }));
        }
Example #2
0
        public ActionResult RemoveFieldFromPOST(string id)
        {
            if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to edit a content part.")))
            {
                return(new HttpUnauthorizedResult());
            }

            var partViewModel = _contentDefinitionService.GetPart(id);

            var viewModel = new RemoveFieldViewModel();

            if (partViewModel == null ||
                !TryUpdateModel(viewModel) ||
                !partViewModel.Fields.Any(p => p.Name == viewModel.Name))
            {
                return(HttpNotFound());
            }

            _contentDefinitionService.RemoveFieldFromPart(viewModel.Name, partViewModel.Name);

            if (!ModelState.IsValid)
            {
                Services.TransactionManager.Cancel();
                viewModel.Part = partViewModel;
                return(View(viewModel));
            }

            Services.Notifier.Information(T("The \"{0}\" field has been removed.", viewModel.Name));

            if (_contentDefinitionService.GetType(id) != null)
            {
                return(RedirectToAction("Edit", new { id }));
            }

            return(RedirectToAction("EditPart", new { id }));
        }
Example #3
0
        public async Task <ActionResult> RemoveFieldFromPOST(string id)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes))
            {
                return(Unauthorized());
            }

            var partViewModel = _contentDefinitionService.GetPart(id);

            var viewModel = new RemoveFieldViewModel();

            if (partViewModel == null ||
                !await TryUpdateModelAsync(viewModel) ||
                !partViewModel.PartDefinition.Fields.Any(p => p.Name == viewModel.Name))
            {
                return(NotFound());
            }

            _contentDefinitionService.RemoveFieldFromPart(viewModel.Name, partViewModel.Name);

            if (!ModelState.IsValid)
            {
                _session.Cancel();
                viewModel.Part = partViewModel;
                return(View(viewModel));
            }

            _notifier.Success(T["The \"{0}\" field has been removed.", viewModel.Name]);

            if (_contentDefinitionService.GetType(id) != null)
            {
                return(RedirectToAction("Edit", new { id }));
            }

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