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 ActionResult EditFieldPOST(string id, EditFieldNameViewModel viewModel) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to edit a content type."))) { return(new HttpUnauthorizedResult()); } if (viewModel == null) { return(HttpNotFound()); } var partViewModel = _contentDefinitionService.GetPart(id); if (partViewModel == null) { return(HttpNotFound()); } // 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", T("字段的显示名称不能为空.").ToString()); } if (_contentDefinitionService.GetPart(partViewModel.Name).Fields.Any(t => t.Name != viewModel.Name && String.Equals(t.DisplayName.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("DisplayName", T("字段的显示名称已经存在.").ToString()); } if (!ModelState.IsValid) { return(View(viewModel)); } var field = _contentDefinitionManager.GetPartDefinition(id).Fields.FirstOrDefault(x => x.Name == viewModel.Name); if (field == null) { return(HttpNotFound()); } _contentDefinitionService.AlterField(partViewModel, viewModel); Services.Notifier.Information(T("显示名称修改为: {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 async Task <ActionResult> EditFieldPOST(string id, EditFieldNameViewModel viewModel) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(new HttpUnauthorizedResult()); } if (viewModel == null) { return(HttpNotFound()); } var partViewModel = _contentDefinitionService.GetPart(id); if (partViewModel == null) { return(HttpNotFound()); } // 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", T["The Display Name name can't be empty."]); } if (_contentDefinitionService.GetPart(partViewModel.Name).Fields.Any(t => t.Name != viewModel.Name && String.Equals(t.DisplayName.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("DisplayName", T["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(HttpNotFound()); } _contentDefinitionService.AlterField(partViewModel, viewModel); //Services.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 async Task <ActionResult> EditFieldPOST(string id, EditFieldViewModel viewModel, string returnUrl = null) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(Forbid()); } if (viewModel == null) { return(NotFound()); } var partViewModel = _contentDefinitionService.LoadPart(id); if (partViewModel == null) { return(NotFound()); } var field = _contentDefinitionManager.LoadPartDefinition(id).Fields.FirstOrDefault(x => x.Name == viewModel.Name); if (field == null) { return(NotFound()); } viewModel.PartFieldDefinition = field; 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 can't be empty."]); } if (_contentDefinitionService.LoadPart(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) { // Calls update to build editor shape with the display name validation failures, and other validation errors. viewModel.Shape = await _contentDefinitionDisplayManager.UpdatePartFieldEditorAsync(field, _updateModelAccessor.ModelUpdater); _documentStore.Cancel(); ViewData["ReturnUrl"] = returnUrl; return(View(viewModel)); } _notifier.Information(H["Display name changed to {0}.", viewModel.DisplayName]); } _contentDefinitionService.AlterField(partViewModel, viewModel); // Refresh the local field variable in case it has been altered field = _contentDefinitionManager.LoadPartDefinition(id).Fields.FirstOrDefault(x => x.Name == viewModel.Name); viewModel.Shape = await _contentDefinitionDisplayManager.UpdatePartFieldEditorAsync(field, _updateModelAccessor.ModelUpdater); if (!ModelState.IsValid) { _documentStore.Cancel(); ViewData["ReturnUrl"] = returnUrl; return(View(viewModel)); } else { _notifier.Success(H["The \"{0}\" field settings have been saved.", field.DisplayName()]); } if (!String.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl)) { return(Redirect(returnUrl)); } else { // Redirect to the type editor if a type exists with this name var typeViewModel = _contentDefinitionService.LoadType(id); if (typeViewModel != null) { return(RedirectToAction("Edit", new { id })); } return(RedirectToAction("EditPart", new { id })); } }