public EditPartFieldViewModel(int index, ContentPartFieldDefinition field) { Index = index; Name = field.Name; FieldDefinition = new EditFieldViewModel(field.FieldDefinition); Settings = field.Settings; _Definition = field; }
public async Task<ActionResult> EditFieldPOST(string id, EditFieldViewModel 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(); } var field = _contentDefinitionManager.GetPartDefinition(id).Fields.FirstOrDefault(x => x.Name == viewModel.Name); if (field == null) { return NotFound(); } if (field.DisplayName() != viewModel.DisplayName) { // prevent null reference exception in validation viewModel.DisplayName = viewModel.DisplayName?.Trim() ?? String.Empty; 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) { _session.Cancel(); return View(viewModel); } _contentDefinitionService.AlterField(partViewModel, viewModel); _notifier.Information(T["Display name changed to {0}.", viewModel.DisplayName]); } viewModel.Editor = await _contentDefinitionDisplayManager.UpdatePartFieldEditorAsync(field, this); if (!ModelState.IsValid) { _session.Cancel(); return View(viewModel); } else { _notifier.Success(T["The \"{0}\" field settings have been saved.", field.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 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 partFieldDefinition = partViewModel.PartDefinition.Fields.FirstOrDefault(x => x.Name == name); if (partFieldDefinition == null) { return NotFound(); } var viewModel = new EditFieldViewModel { Name = partFieldDefinition.Name, DisplayName = partFieldDefinition.DisplayName(), PartFieldDefinition = partFieldDefinition, Editor = await _contentDefinitionDisplayManager.BuildPartFieldEditorAsync(partFieldDefinition, this) }; return View(viewModel); }
public void AlterField(EditPartViewModel partViewModel, EditFieldViewModel fieldViewModel) { _contentDefinitionManager.AlterPartDefinition(partViewModel.Name, partBuilder => { partBuilder.WithField(fieldViewModel.Name, fieldBuilder => { fieldBuilder.WithDisplayName(fieldViewModel.DisplayName); }); }); }