public EditTypeViewModel GetType(string name) { var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(name); if (contentTypeDefinition == null) { return(null); } var viewModel = new EditTypeViewModel(contentTypeDefinition) { Templates = _contentDefinitionEditorEvents.TypeEditor(contentTypeDefinition) }; foreach (var part in viewModel.Parts) { part._Definition.ContentTypeDefinition = contentTypeDefinition; part.Templates = _contentDefinitionEditorEvents.TypePartEditor(part._Definition); foreach (var field in part.PartDefinition.Fields) { field.Templates = _contentDefinitionEditorEvents.PartFieldEditor(field._Definition); } } if (viewModel.Fields.Any()) { foreach (var field in viewModel.Fields) { field.Templates = _contentDefinitionEditorEvents.PartFieldEditor(field._Definition); } } return(viewModel); }
public async Task <ActionResult> CreatePOST(CreateTypeViewModel viewModel) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(Forbid()); } viewModel.DisplayName = viewModel.DisplayName?.Trim() ?? String.Empty; viewModel.Name = viewModel.Name ?? String.Empty; if (String.IsNullOrWhiteSpace(viewModel.DisplayName)) { ModelState.AddModelError("DisplayName", S["The Display Name can't be empty."]); } if (_contentDefinitionService.LoadTypes().Any(t => String.Equals(t.DisplayName.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("DisplayName", S["A type with the same Display Name already exists."]); } if (String.IsNullOrWhiteSpace(viewModel.Name)) { ModelState.AddModelError("Name", S["The Technical Name can't be empty."]); } if (!String.IsNullOrWhiteSpace(viewModel.Name) && !viewModel.Name[0].IsLetter()) { ModelState.AddModelError("Name", S["The Technical Name must start with a letter."]); } if (!String.Equals(viewModel.Name, viewModel.Name.ToSafeName(), StringComparison.OrdinalIgnoreCase)) { ModelState.AddModelError("Name", S["The Technical Name contains invalid characters."]); } if (viewModel.Name.IsReservedContentName()) { ModelState.AddModelError("Name", S["The Technical Name is reserved for internal use."]); } if (_contentDefinitionService.LoadTypes().Any(t => String.Equals(t.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("Name", S["A type with the same Technical Name already exists."]); } if (!ModelState.IsValid) { await _documentStore.CancelAsync(); return(View(viewModel)); } var contentTypeDefinition = _contentDefinitionService.AddType(viewModel.Name, viewModel.DisplayName); var typeViewModel = new EditTypeViewModel(contentTypeDefinition); await _notifier.SuccessAsync(H["The \"{0}\" content type has been created.", typeViewModel.DisplayName]); return(RedirectToAction("AddPartsTo", new { id = typeViewModel.Name })); }
public void CreateEntity(EditTypeViewModel sourceModel) { var entityDraft = Services.ContentManager.New <EntityMetadataPart>("EntityMetadata"); var baseFieldSetting = new SettingsDictionary { { "DisplayName", sourceModel.FieldLabel }, { "AddInLayout", bool.TrueString }, { "Storage", "Part" }, { "CoeveryTextFieldSettings.IsDispalyField", bool.TrueString }, { "CoeveryTextFieldSettings.Required", bool.TrueString }, { "CoeveryTextFieldSettings.ReadOnly", bool.TrueString }, { "CoeveryTextFieldSettings.AlwaysInLayout", bool.TrueString }, { "CoeveryTextFieldSettings.IsSystemField", bool.TrueString }, { "CoeveryTextFieldSettings.IsAudit", bool.FalseString } }; entityDraft.DisplayName = sourceModel.DisplayName; entityDraft.Name = sourceModel.Name; entityDraft.FieldMetadataRecords.Add(new FieldMetadataRecord { Name = sourceModel.FieldName, ContentFieldDefinitionRecord = FetchFieldDefinition("CoeveryTextField"), Settings = CompileSetting(baseFieldSetting) }); Services.ContentManager.Create(entityDraft, VersionOptions.Draft); }
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 CreatePOST(CreateTypeViewModel viewModel) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to create a content type."))) { return(new HttpUnauthorizedResult()); } viewModel.DisplayName = viewModel.DisplayName ?? String.Empty; viewModel.Name = viewModel.Name ?? String.Empty; if (String.IsNullOrWhiteSpace(viewModel.DisplayName)) { ModelState.AddModelError("DisplayName", T("The Display Name name can't be empty.").ToString()); } if (String.IsNullOrWhiteSpace(viewModel.Name)) { ModelState.AddModelError("Name", T("The Content Type Id can't be empty.").ToString()); } if (_contentDefinitionService.GetTypes().Any(t => String.Equals(t.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("Name", T("A type with the same Id already exists.").ToString()); } if (!String.IsNullOrWhiteSpace(viewModel.Name) && !viewModel.Name[0].IsLetter()) { ModelState.AddModelError("Name", T("The technical name must start with a letter.").ToString()); } if (_contentDefinitionService.GetTypes().Any(t => String.Equals(t.DisplayName.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("DisplayName", T("A type with the same Display Name already exists.").ToString()); } if (!ModelState.IsValid) { Services.TransactionManager.Cancel(); return(View(viewModel)); } var contentTypeDefinition = _contentDefinitionService.AddType(viewModel.Name, viewModel.DisplayName); // adds CommonPart by default _contentDefinitionService.AddPartToType("CommonPart", viewModel.Name); var typeViewModel = new EditTypeViewModel(contentTypeDefinition); Services.Notifier.Information(T("The \"{0}\" content type has been created.", typeViewModel.DisplayName)); return(RedirectToAction("AddPartsTo", new { id = typeViewModel.Name })); }
public async Task <ActionResult> CreatePOST(CreateTypeViewModel viewModel) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(Unauthorized()); } viewModel.DisplayName = viewModel.DisplayName ?? String.Empty; viewModel.Name = viewModel.Name ?? String.Empty; if (String.IsNullOrWhiteSpace(viewModel.DisplayName)) { ModelState.AddModelError("DisplayName", S["The Display Name can't be empty."]); } if (String.IsNullOrWhiteSpace(viewModel.Name)) { ModelState.AddModelError("Name", S["The Content Type Id can't be empty."]); } if (_contentDefinitionService.GetTypes().Any(t => String.Equals(t.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("Name", S["A type with the same Id already exists."]); } if (!String.IsNullOrWhiteSpace(viewModel.Name) && !viewModel.Name[0].IsLetter()) { ModelState.AddModelError("Name", S["The technical name must start with a letter."]); } if (_contentDefinitionService.GetTypes().Any(t => String.Equals(t.DisplayName.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("DisplayName", S["A type with the same Display Name already exists."]); } if (!ModelState.IsValid) { _session.Cancel(); return(View(viewModel)); } var contentTypeDefinition = _contentDefinitionService.AddType(viewModel.Name, viewModel.DisplayName); var typeViewModel = new EditTypeViewModel(contentTypeDefinition); _notifier.Success(T["The \"{0}\" content type has been created.", typeViewModel.DisplayName]); return(RedirectToAction("AddPartsTo", new { id = typeViewModel.Name })); }
public ActionResult CreateAJAX(CreateTypeViewModel viewModel) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("无权限."))) { return(Json(new { State = 0, Msg = "无权限操作" })); } viewModel.DisplayName = viewModel.DisplayName ?? String.Empty; viewModel.Name = viewModel.Name ?? String.Empty; if (String.IsNullOrWhiteSpace(viewModel.DisplayName)) { return(Json(new { State = 0, Msg = T("显示名称不能为空.").ToString() })); } if (String.IsNullOrWhiteSpace(viewModel.Name)) { return(Json(new { State = 0, Msg = T("内容类型ID不能为空.").ToString() })); } if (_contentDefinitionService.GetTypes().Any(t => String.Equals(t.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase))) { return(Json(new { State = 0, Msg = T("内容类型ID已存在.").ToString() })); } if (!String.IsNullOrWhiteSpace(viewModel.Name) && !viewModel.Name[0].IsLetter()) { return(Json(new { State = 0, Msg = T("内容类型ID必须以字母开头.").ToString() })); } if (_contentDefinitionService.GetTypes().Any(t => String.Equals(t.DisplayName.Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase))) { return(Json(new { State = 0, Msg = T("显示名称已存在.").ToString() })); } if (!ModelState.IsValid) { Services.TransactionManager.Cancel(); return(Json(new { State = 0, Msg = T("数据校验未通过.").ToString() })); } var contentTypeDefinition = _contentDefinitionService.AddType(viewModel.Name, viewModel.DisplayName); // adds CommonPart by default _contentDefinitionService.AddPartToType("CommonPart", viewModel.Name); var typeViewModel = new EditTypeViewModel(contentTypeDefinition); return(Json(new { State = 1, Msg = Url.Action("AddPartsTo", new { id = typeViewModel.Name }) })); }
public void AlterType(EditTypeViewModel typeViewModel, ContentManagement.IUpdateModel updateModel) { var updater = new Updater(updateModel); _contentDefinitionManager.AlterTypeDefinition(typeViewModel.Name, typeBuilder => { typeBuilder.DisplayedAs(typeViewModel.Description); foreach (var part in typeViewModel.Parts) { // enable updater to be aware of changing part prefix updater._prefix = secondHalf => String.Format("{0}.{1}", part.Prefix, secondHalf); typeBuilder.WithPart(part.PartName, part.Index); } }); }
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")); }
public ActionResult EditPOST(string id) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to edit a content type."))) { 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("Index")); }
public EditTypeViewModel GetType(string name) { var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(name); if (contentTypeDefinition == null) { return(null); } var viewModel = new EditTypeViewModel(contentTypeDefinition) { //Templates = _contentDefinitionEditorEvents.TypeEditor(contentTypeDefinition) }; return(viewModel); }
public async Task <ActionResult> EditPOST(string id, EditTypeViewModel viewModel) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(Unauthorized()); } var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(id); if (contentTypeDefinition == null) { return(NotFound()); } viewModel.Settings = contentTypeDefinition.Settings; viewModel.TypeDefinition = contentTypeDefinition; viewModel.DisplayName = contentTypeDefinition.DisplayName; viewModel.Editor = await _contentDefinitionDisplayManager.UpdateTypeEditorAsync(contentTypeDefinition, this); if (!ModelState.IsValid) { _session.Cancel(); HackModelState(nameof(EditTypeViewModel.OrderedFieldNames)); HackModelState(nameof(EditTypeViewModel.OrderedPartNames)); return(View(viewModel)); } else { var ownedPartDefinition = _contentDefinitionManager.GetPartDefinition(contentTypeDefinition.Name); if (ownedPartDefinition != null && viewModel.OrderedFieldNames != null) { _contentDefinitionService.AlterPartFieldsOrder(ownedPartDefinition, viewModel.OrderedFieldNames); } _contentDefinitionService.AlterTypePartsOrder(contentTypeDefinition, viewModel.OrderedPartNames); _notifier.Success(T["\"{0}\" settings have been saved.", contentTypeDefinition.Name]); } return(RedirectToAction("Edit", new { id })); }
public ActionResult EditAJAX(string id) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("无权限."))) { return(Json(new { State = 0, Msg = "无权限" })); } var typeViewModel = _contentDefinitionService.GetType(id); if (typeViewModel == null) { return(Json(new { State = 0, Msg = "内容类型不存在" })); } var edited = new EditTypeViewModel(); TryUpdateModel(edited); typeViewModel.DisplayName = edited.DisplayName ?? string.Empty; if (String.IsNullOrWhiteSpace(typeViewModel.DisplayName)) { Services.TransactionManager.Cancel(); return(Json(new { State = 0, Msg = T("显示名称不能为空.").ToString() })); } if (_contentDefinitionService.GetTypes().Any(t => String.Equals(t.DisplayName.Trim(), typeViewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase) && !String.Equals(t.Name, id))) { Services.TransactionManager.Cancel(); return(Json(new { State = 0, Msg = T("显示名称已存在.").ToString() })); } _contentDefinitionService.AlterType(typeViewModel, this); if (!ModelState.IsValid) { Services.TransactionManager.Cancel(); return(Json(new { State = 0, Msg = T("数据校验不正确.").ToString() })); } return(Json(new { State = 1, Msg = T("\"{0}\" 修改成功.", typeViewModel.DisplayName).Text })); }
public void AlterType(EditTypeViewModel typeViewModel, IUpdateModel updateModel) { var updater = new Updater(updateModel); _contentDefinitionManager.AlterTypeDefinition(typeViewModel.Name, typeBuilder => { typeBuilder.DisplayedAs(typeViewModel.DisplayName); // allow extensions to alter type configuration _contentDefinitionEditorEvents.TypeEditorUpdating(typeBuilder); typeViewModel.Templates = _contentDefinitionEditorEvents.TypeEditorUpdate(typeBuilder, updater); _contentDefinitionEditorEvents.TypeEditorUpdated(typeBuilder); foreach (var part in typeViewModel.Parts) { var partViewModel = part; // enable updater to be aware of changing part prefix updater.Prefix = secondHalf => String.Format("{0}.{1}", partViewModel.Prefix, secondHalf); // allow extensions to alter typePart configuration typeBuilder.WithPart(partViewModel.PartDefinition.Name, typePartBuilder => { _contentDefinitionEditorEvents.TypePartEditorUpdating(typePartBuilder); partViewModel.Templates = _contentDefinitionEditorEvents.TypePartEditorUpdate(typePartBuilder, updater); _contentDefinitionEditorEvents.TypePartEditorUpdated(typePartBuilder); }); if (!partViewModel.PartDefinition.Fields.Any()) { continue; } _contentDefinitionManager.AlterPartDefinition(partViewModel.PartDefinition.Name, partBuilder => { var fieldFirstHalf = String.Format("{0}.{1}", partViewModel.Prefix, partViewModel.PartDefinition.Prefix); foreach (var field in partViewModel.PartDefinition.Fields) { var fieldViewModel = field; // enable updater to be aware of changing field prefix updater.Prefix = secondHalf => String.Format("{0}.{1}.{2}", fieldFirstHalf, fieldViewModel.Prefix, secondHalf); // allow extensions to alter partField configuration partBuilder.WithField(fieldViewModel.Name, partFieldBuilder => { _contentDefinitionEditorEvents.PartFieldEditorUpdating(partFieldBuilder); fieldViewModel.Templates = _contentDefinitionEditorEvents.PartFieldEditorUpdate(partFieldBuilder, updater); _contentDefinitionEditorEvents.PartFieldEditorUpdated(partFieldBuilder); }); } }); } if (typeViewModel.Fields.Any()) { _contentDefinitionManager.AlterPartDefinition(typeViewModel.Name, partBuilder => { foreach (var field in typeViewModel.Fields) { var fieldViewModel = field; // enable updater to be aware of changing field prefix updater.Prefix = secondHalf => string.Format("{0}.{1}", fieldViewModel.Prefix, secondHalf); // allow extensions to alter partField configuration partBuilder.WithField(fieldViewModel.Name, partFieldBuilder => { _contentDefinitionEditorEvents.PartFieldEditorUpdating(partFieldBuilder); fieldViewModel.Templates = _contentDefinitionEditorEvents.PartFieldEditorUpdate(partFieldBuilder, updater); _contentDefinitionEditorEvents.PartFieldEditorUpdated(partFieldBuilder); }); } }); } }); }