public ActionResult CreatePost(EditTypeViewModel viewModel) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to create a content type."))) { return(new HttpUnauthorizedResult()); } viewModel.DisplayName = string.IsNullOrWhiteSpace(viewModel.DisplayName) ? String.Empty : viewModel.DisplayName.Trim(); viewModel.Name = (viewModel.Name ?? viewModel.DisplayName).ToSafeName(); viewModel.FieldLabel = string.IsNullOrWhiteSpace(viewModel.FieldLabel) ? String.Empty : viewModel.FieldLabel.Trim(); viewModel.FieldName = (viewModel.FieldName ?? viewModel.FieldLabel).ToSafeName(); 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()); } else if (!PluralizationService.CreateService(new CultureInfo("en-US")).IsSingular(viewModel.Name)) { ModelState.AddModelError("Name", T("The name should be singular.").ToString()); } if (String.IsNullOrWhiteSpace(viewModel.FieldLabel)) { ModelState.AddModelError("DisplayName", T("The Field Label name can't be empty.").ToString()); } if (String.IsNullOrWhiteSpace(viewModel.FieldName)) { ModelState.AddModelError("Name", T("The Field Name can't be empty.").ToString()); } else if (!PluralizationService.CreateService(new CultureInfo("en-US")).IsSingular(viewModel.FieldName)) { ModelState.AddModelError("FieldName", T("The field name should be singular.").ToString()); } if (!_contentMetadataService.CheckEntityCreationValid(viewModel.Name, viewModel.DisplayName)) { ModelState.AddModelError("Name", T("A type with the same Name or DisplayName already exists.").ToString()); } if (!ModelState.IsValid) { Services.TransactionManager.Cancel(); Response.StatusCode = (int)HttpStatusCode.BadRequest; var temp = (from values in ModelState from error in values.Value.Errors select error.ErrorMessage).ToArray(); return(Content(string.Concat(temp))); } _contentMetadataService.CreateEntity(viewModel); return(Json(new { entityName = viewModel.Name })); }
public ActionResult Edit(string id) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to edit a content type."))) { return(new HttpUnauthorizedResult()); } var entity = _contentMetadataService.GetEntity(id); if (entity == null) { return(HttpNotFound()); } var viewModel = new EditTypeViewModel { Name = entity.Name, DisplayName = entity.DisplayName }; return(View(viewModel)); }
public ActionResult EditPost(string id, EditTypeViewModel viewModel) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to edit a content type."))) { return(new HttpUnauthorizedResult()); } var entity = _contentMetadataService.GetDraftEntity(id); if (entity == null) { return(HttpNotFound()); } bool valid = _contentMetadataService.CheckEntityDisplayValid(id, viewModel.DisplayName); if (!valid) { return(new HttpStatusCodeResult(HttpStatusCode.MethodNotAllowed)); } entity.DisplayName = viewModel.DisplayName; return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
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); }