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

            if (viewModel == null)
                return NotFound();

            var partViewModel = _contentDefinitionService.GetPart(id);

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

            // prevent null reference exception in validation
            viewModel.DisplayName = viewModel.DisplayName ?? String.Empty;

            // remove extra spaces
            viewModel.DisplayName = viewModel.DisplayName.Trim();

            if (String.IsNullOrWhiteSpace(viewModel.DisplayName))
            {
                ModelState.AddModelError("DisplayName", S["The Display Name name can't be empty."]);
            }

            if (_contentDefinitionService.GetPart(partViewModel.Name).PartDefinition.Fields.Any(t => t.Name != viewModel.Name && String.Equals(t.DisplayName.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase)))
            {
                ModelState.AddModelError("DisplayName", S["A field with the same Display Name already exists."]);
            }

            if (!ModelState.IsValid)
            {
                return View(viewModel);
            }

            var field = _contentDefinitionManager.GetPartDefinition(id).Fields.FirstOrDefault(x => x.Name == viewModel.Name);

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

            _contentDefinitionService.AlterField(partViewModel, viewModel);

            _notifier.Information(T["Display name changed to {0}.", viewModel.DisplayName]);

            // redirect to the type editor if a type exists with this name
            var typeViewModel = _contentDefinitionService.GetType(id);
            if (typeViewModel != null)
            {
                return RedirectToAction("Edit", new { id });
            }

            return RedirectToAction("EditPart", new { id });
        }
 public void AlterField(EditPartViewModel partViewModel, EditFieldNameViewModel fieldViewModel)
 {
     _contentDefinitionManager.AlterPartDefinition(partViewModel.Name, partBuilder =>
     {
         partBuilder.WithField(fieldViewModel.Name, fieldBuilder =>
         {
             fieldBuilder.WithDisplayName(fieldViewModel.DisplayName);
         });
     });
 }
Beispiel #3
0
        public async Task<ActionResult> EditField(string id, string name)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes))
                return Unauthorized();

            var partViewModel = _contentDefinitionService.GetPart(id);

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

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

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

            var viewModel = new EditFieldNameViewModel
            {
                Name = fieldViewModel.Name,
                DisplayName = fieldViewModel.DisplayName
            };

            return View(viewModel);
        }
 public void AlterField(EditPartViewModel partViewModel, EditFieldNameViewModel fieldViewModel)
 {
     _contentDefinitionManager.AlterPartDefinition(partViewModel.Name, partBuilder =>
     {
         partBuilder.WithField(fieldViewModel.Name, fieldBuilder =>
         {
             _contentDefinitionEditorEvents.Invoke(x => x.PartFieldEditorUpdating(fieldBuilder), Logger);
             fieldBuilder.WithDisplayName(fieldViewModel.DisplayName);
             _contentDefinitionEditorEvents.Invoke(x => x.PartFieldEditorUpdated(fieldBuilder), Logger);
         });
     });
 }