public ActionResult EditPOST(string id, EditTypeViewModel model) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, "Not allowed to edit a content type.")) { return(new HttpUnauthorizedResult()); } var typeViewModel = _contentDefinitionService.GetType(id); if (typeViewModel == null) { return(HttpNotFound()); } if (!ModelState.IsValid) { return(View(typeViewModel)); } _contentDefinitionService.AlterType(model, this); if (!ModelState.IsValid) { Services.TransactionManager.Cancel(); return(View(typeViewModel)); } Services.Notifier.Information(string.Format("\"{0}\" settings have been saved.", typeViewModel.Name)); return(RedirectToAction("Index")); }
public ActionResult EditPOST(string id) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("无权限."))) { return(new HttpUnauthorizedResult()); } var typeViewModel = _contentDefinitionService.GetType(id); if (typeViewModel == null) { return(HttpNotFound()); } var edited = new EditTypeViewModel(); TryUpdateModel(edited); typeViewModel.DisplayName = edited.DisplayName ?? string.Empty; if (String.IsNullOrWhiteSpace(typeViewModel.DisplayName)) { ModelState.AddModelError("DisplayName", T("The Content Type name can't be empty.").ToString()); } if (_contentDefinitionService.GetTypes().Any(t => String.Equals(t.DisplayName.Trim(), typeViewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase) && !String.Equals(t.Name, id))) { ModelState.AddModelError("DisplayName", T("A type with the same name already exists.").ToString()); } if (!ModelState.IsValid) { return(View(typeViewModel)); } _contentDefinitionService.AlterType(typeViewModel, this); if (!ModelState.IsValid) { Services.TransactionManager.Cancel(); return(View(typeViewModel)); } Services.Notifier.Information(T("\"{0}\" settings have been saved.", typeViewModel.DisplayName)); return(RedirectToAction("Edit", new { id })); }
public async Task <ActionResult> EditPOST(string id) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(new HttpUnauthorizedResult()); } var typeViewModel = _contentDefinitionService.GetType(id); if (typeViewModel == null) { return(HttpNotFound()); } var edited = new EditTypeViewModel(); await TryUpdateModelAsync(edited); typeViewModel.DisplayName = edited.DisplayName ?? string.Empty; if (String.IsNullOrWhiteSpace(typeViewModel.DisplayName)) { ModelState.AddModelError("DisplayName", T["The Content Type name can't be empty."]); } if (_contentDefinitionService.GetTypes().Any(t => String.Equals(t.DisplayName.Trim(), typeViewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase) && !String.Equals(t.Name, id))) { ModelState.AddModelError("DisplayName", T["A type with the same name already exists."]); } if (!ModelState.IsValid) { return(View(typeViewModel)); } _contentDefinitionService.AlterType(typeViewModel, this); if (!ModelState.IsValid) { _session.Cancel(); return(View(typeViewModel)); } //Services.Notifier.Information(T("\"{0}\" settings have been saved.", typeViewModel.DisplayName)); return(RedirectToAction("List")); }