public async Task <ActionResult> EditTypePart(string id, string name) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(Unauthorized()); } var typeDefinition = _contentDefinitionManager.GetTypeDefinition(id); if (typeDefinition == null) { return(NotFound()); } var typePartDefinition = typeDefinition.Parts.FirstOrDefault(x => x.Name == name); if (typePartDefinition == null) { return(NotFound()); } var typePartViewModel = new EditTypePartViewModel { Name = typePartDefinition.Name, DisplayName = typePartDefinition.DisplayName(), Description = typePartDefinition.Description(), TypePartDefinition = typePartDefinition, Editor = await _contentDefinitionDisplayManager.BuildTypePartEditorAsync(typePartDefinition, this) }; return(View(typePartViewModel)); }
public void AlterTypePart(EditTypePartViewModel typePartViewModel) { var typeDefinition = typePartViewModel.TypePartDefinition.ContentTypeDefinition; _contentDefinitionManager.AlterTypeDefinition(typeDefinition.Name, type => { type.WithPart(typePartViewModel.Name, typePartViewModel.TypePartDefinition.PartDefinition, part => { part.WithDisplayName(typePartViewModel.DisplayName); part.WithDescription(typePartViewModel.Description); }); }); }
public async Task <ActionResult> EditTypePartPOST(string id, EditTypePartViewModel viewModel) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(Unauthorized()); } if (viewModel == null) { return(NotFound()); } var typeDefinition = _contentDefinitionManager.GetTypeDefinition(id); if (typeDefinition == null) { return(NotFound()); } var part = typeDefinition.Parts.FirstOrDefault(x => x.Name == viewModel.Name); if (part == null) { return(NotFound()); } viewModel.TypePartDefinition = part; if (part.PartDefinition.IsReusable()) { if (part.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 (typeDefinition.Parts.Any(t => t.Name != viewModel.Name && String.Equals(t.DisplayName()?.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("DisplayName", S["A part with the same display name already exists."]); } if (!ModelState.IsValid) { _session.Cancel(); return(View(viewModel)); } } _contentDefinitionService.AlterTypePart(viewModel); } viewModel.Editor = await _contentDefinitionDisplayManager.UpdateTypePartEditorAsync(part, this); if (!ModelState.IsValid) { _session.Cancel(); return(View(viewModel)); } else { _notifier.Success(T["The \"{0}\" part settings have been saved.", part.DisplayName()]); } return(RedirectToAction("Edit", new { id })); }
public async Task <ActionResult> EditTypePartPOST(string id, EditTypePartViewModel viewModel) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(Forbid()); } if (viewModel == null) { return(NotFound()); } var typeDefinition = _contentDefinitionManager.LoadTypeDefinition(id); if (typeDefinition == null) { return(NotFound()); } var part = typeDefinition.Parts.FirstOrDefault(x => x.Name == viewModel.Name); if (part == null) { return(NotFound()); } viewModel.TypePartDefinition = part; if (part.PartDefinition.IsReusable()) { if (part.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 (typeDefinition.Parts.Any(t => t.Name != viewModel.Name && String.Equals(t.DisplayName()?.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("DisplayName", S["A part with the same Display Name already exists."]); } if (!ModelState.IsValid) { viewModel.Shape = await _contentDefinitionDisplayManager.UpdateTypePartEditorAsync(part, _updateModelAccessor.ModelUpdater); await _documentStore.CancelAsync(); return(View(viewModel)); } } } _contentDefinitionService.AlterTypePart(viewModel); // Refresh the local part variable in case it has been altered part = _contentDefinitionManager.LoadTypeDefinition(id).Parts.FirstOrDefault(x => x.Name == viewModel.Name); viewModel.Shape = await _contentDefinitionDisplayManager.UpdateTypePartEditorAsync(part, _updateModelAccessor.ModelUpdater); if (!ModelState.IsValid) { await _documentStore.CancelAsync(); return(View(viewModel)); } else { await _notifier.SuccessAsync(H["The \"{0}\" part settings have been saved.", part.DisplayName()]); } return(RedirectToAction(nameof(Edit), new { id })); }
public void AlterTypePart(EditTypePartViewModel partViewModel) => throw new NotImplementedException();