public async Task <ActionResult> AddFieldTo(string id) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(Unauthorized()); } var partViewModel = _contentDefinitionService.GetPart(id); if (partViewModel == null) { //id passed in might be that of a type w/ no implicit field var typeViewModel = _contentDefinitionService.GetType(id); if (typeViewModel != null) { partViewModel = new EditPartViewModel(new ContentPartDefinition(id)); } else { return(NotFound()); } } var viewModel = new AddFieldViewModel { Part = partViewModel, Fields = _contentDefinitionService.GetFields().OrderBy(x => x.FieldTypeName).ToList() }; return(View(viewModel)); }
public async Task <IActionResult> AddFieldModal(AddFieldViewModel model) { Result result = new Result(); try { if (model.Type == 0 || String.IsNullOrEmpty(model.Name)) { result.ErrorCode = ErrorCode.INVALID_INPUT; result.Message = "Please fill in the required field"; result.Success = false; return(Json(result)); } var user = await _userManager.GetUserAsync(HttpContext.User); result = await _maintenanceService.CreateField(_mapper.Map <AddFieldDTO>(model), user.ToString()); var subModuleField = new AddSubModuleFieldDTO(); subModuleField.FieldId = Convert.ToInt32(result.Id); subModuleField.SubModuleId = model.SubModuleId; subModuleField.Order = await _queryService.GetSubModuleFieldMaxOrder(model.SubModuleId); result = await _maintenanceService.AddSubModuleField(subModuleField); } catch (Exception e) { _logger.LogError("Error Exception on AddFieldModal: " + e.Message.ToString()); } return(Json(result)); }
public ActionResult AddFieldTo(string id) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to edit a content part."))) { return(new HttpUnauthorizedResult()); } var partViewModel = _contentDefinitionService.GetPart(id); if (partViewModel == null) { //id passed in might be that of a type w/ no implicit field var typeViewModel = _contentDefinitionService.GetType(id); if (typeViewModel != null) { partViewModel = new EditPartViewModel(new ContentPartDefinition(id)); } else { return(HttpNotFound()); } } var viewModel = new AddFieldViewModel { Part = partViewModel, Fields = _contentDefinitionService.GetFields().OrderBy(x => x.FieldTypeName) }; return(View(viewModel)); }
public async Task <IActionResult> AddLifeCycleField(AddFieldViewModel model) { Result result = new Result(); var user = await _userManager.GetUserAsync(HttpContext.User); string userId = HttpContext.Session.GetString(SessionHelper.USER_ID); result = await _maintenanceService.CreateLifeCycleField(_mapper.Map <AddFieldDTO>(model), userId); if (!result.Success) { return(Json(result)); } var subModuleField = new AddSubModuleFieldDTO(); subModuleField.FieldId = Convert.ToInt32(result.Id); //hard coded, rework this subModuleField.SubModuleId = Convert.ToInt32(model.LifeCycle) + 1; subModuleField.Order = await _queryService.GetSubModuleFieldMaxOrder(model.SubModuleId); result = await _maintenanceService.AddSubModuleField(subModuleField); //redirect to user list after add if (result.Success) { result.IsRedirect = true; result.RedirectUrl = "Maintenance/LifeCycleField"; } return(Json(result)); }
public string CreateRelationship(OneToManyRelationshipModel oneToMany) { if (oneToMany == null) { return("Invalid model."); } var primaryEntity = _contentMetadataService.GetEntity(oneToMany.PrimaryEntity); var relatedEntity = _contentMetadataService.GetDraftEntity(oneToMany.RelatedEntity); if (primaryEntity == null || relatedEntity == null || !primaryEntity.HasPublished()) { return("Invalid entity"); } if (RelationshipExists(oneToMany.Name)) { return("Name already exist."); } var relationship = CreateRelation(new RelationshipRecord { Name = oneToMany.Name, PrimaryEntity = primaryEntity.Record, RelatedEntity = relatedEntity.Record, Type = (byte)RelationshipType.OneToMany }); var updateModel = new ReferenceUpdateModel(new ReferenceFieldSettings { AlwaysInLayout = oneToMany.AlwaysInLayout, ContentTypeName = oneToMany.PrimaryEntity, DisplayAsLink = oneToMany.DisplayAsLink, HelpText = oneToMany.HelpText, IsAudit = oneToMany.IsAudit, Required = oneToMany.Required, RelationshipId = relationship.Id, RelationshipName = relationship.Name }); var fieldViewModel = new AddFieldViewModel { AddInLayout = true, Name = oneToMany.FieldName, DisplayName = oneToMany.FieldLabel, FieldTypeName = "ReferenceField" }; _contentMetadataService.CreateField(relatedEntity, fieldViewModel, updateModel); var fieldRecord = relatedEntity.FieldMetadataRecords.FirstOrDefault(field => field.Name == oneToMany.FieldName); var projectionPart = CreateProjection(oneToMany.RelatedEntity, oneToMany.ColumnFieldList); _oneToManyRepository.Create(new OneToManyRelationshipRecord { DeleteOption = (byte)oneToMany.DeleteOption, LookupField = fieldRecord, RelatedListProjection = projectionPart.Record, RelatedListLabel = oneToMany.RelatedListLabel, Relationship = relationship, ShowRelatedList = oneToMany.ShowRelatedList }); return(relationship.Id.ToString()); }
public ActionResult CreateChooseType(string id) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to edit a content part."))) { return(new HttpUnauthorizedResult()); } var viewModel = new AddFieldViewModel { Fields = _contentDefinitionService.GetFields().OrderBy(x => x.TemplateName), }; return(View(viewModel)); }
public void CreateField(EntityMetadataPart entity, AddFieldViewModel viewModel, IUpdateModel updateModel) { var settingsDictionary = new SettingsDictionary(); settingsDictionary["DisplayName"] = viewModel.DisplayName; settingsDictionary["AddInLayout"] = viewModel.AddInLayout.ToString(); settingsDictionary["EntityName"] = entity.Name; var field = new FieldMetadataRecord { ContentFieldDefinitionRecord = FetchFieldDefinition(viewModel.FieldTypeName), Name = viewModel.Name }; entity.FieldMetadataRecords.Add(field); _contentDefinitionEditorEvents.UpdateFieldSettings(viewModel.FieldTypeName, viewModel.Name, settingsDictionary, updateModel); field.Settings = CompileSetting(settingsDictionary); field.EntityMetadataRecord = entity.Record; }
public ActionResult CreateEditInfo(string id, string fieldTypeName) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to edit a content part."))) { return(new HttpUnauthorizedResult()); } var contentFieldDefinition = new ContentFieldDefinition(fieldTypeName); var definition = new ContentPartFieldDefinition(contentFieldDefinition, string.Empty, new SettingsDictionary()); var templates = _contentDefinitionEditorEvents.PartFieldEditor(definition); var viewModel = new AddFieldViewModel { FieldTypeName = fieldTypeName, TypeTemplates = templates, AddInLayout = true }; return(View(viewModel)); }
public async Task <IActionResult> AddField(AddFieldViewModel model) { Result result = new Result(); var user = await _userManager.GetUserAsync(HttpContext.User); string userId = HttpContext.Session.GetString(SessionHelper.USER_ID); result = await _maintenanceService.CreateField(_mapper.Map <AddFieldDTO>(model), userId); //redirect to user list after add if (result.Success) { result.IsRedirect = true; result.RedirectUrl = "Maintenance/Field"; } return(Json(result)); }
public async Task <ActionResult> AddFieldTo(string id) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(Unauthorized()); } var partViewModel = _contentDefinitionService.GetPart(id); if (partViewModel == null) { return(NotFound()); } var viewModel = new AddFieldViewModel { Part = partViewModel.PartDefinition, Fields = _contentDefinitionService.GetFields().Select(x => x.Name).OrderBy(x => x).ToList() }; return(View(viewModel)); }
public async Task <ActionResult> AddFieldToPOST(AddFieldViewModel viewModel, string id) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(Unauthorized()); } var partViewModel = _contentDefinitionService.GetPart(id); var typeViewModel = _contentDefinitionService.GetType(id); if (partViewModel == null) { // id passed in might be that of a type w/ no implicit field if (typeViewModel != null) { partViewModel = new EditPartViewModel { Name = typeViewModel.Name }; _contentDefinitionService.AddPart(new CreatePartViewModel { Name = partViewModel.Name }); _contentDefinitionService.AddPartToType(partViewModel.Name, typeViewModel.Name); } else { return(NotFound()); } } viewModel.DisplayName = viewModel.DisplayName ?? String.Empty; viewModel.DisplayName = viewModel.DisplayName.Trim(); viewModel.Name = viewModel.Name ?? String.Empty; if (String.IsNullOrWhiteSpace(viewModel.DisplayName)) { ModelState.AddModelError("DisplayName", S["The Display Name name can't be empty."]); } if (String.IsNullOrWhiteSpace(viewModel.Name)) { ModelState.AddModelError("Name", S["The Technical Name can't be empty."]); } if (_contentDefinitionService.GetPart(partViewModel.Name).PartDefinition.Fields.Any(t => String.Equals(t.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("Name", S["A field with the same name already exists."]); } 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 (_contentDefinitionService.GetPart(partViewModel.Name).PartDefinition.Fields.Any(t => String.Equals(t.DisplayName.Trim(), Convert.ToString(viewModel.DisplayName).Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("DisplayName", S["A field with the same Display Name already exists."]); } if (!ModelState.IsValid) { viewModel.Part = partViewModel; viewModel.Fields = _contentDefinitionService.GetFields(); _session.Cancel(); return(View(viewModel)); } try { _contentDefinitionService.AddFieldToPart(viewModel.Name, viewModel.DisplayName, viewModel.FieldTypeName, partViewModel.Name); } catch { //Services.Notifier.Information(T("The \"{0}\" field was not added. {1}", viewModel.DisplayName, ex.Message)); _session.Cancel(); return(await AddFieldTo(id)); } _notifier.Success(T["The \"{0}\" field has been added.", viewModel.DisplayName]); if (typeViewModel != null) { return(RedirectToAction("Edit", new { id })); } return(RedirectToAction("EditPart", new { id })); }
public ActionResult AddFieldToPOST(AddFieldViewModel viewModel, string id) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to edit a content part."))) { return(new HttpUnauthorizedResult()); } var partViewModel = _contentDefinitionService.GetPart(id); var typeViewModel = _contentDefinitionService.GetType(id); if (partViewModel == null) { // id passed in might be that of a type w/ no implicit field if (typeViewModel != null) { partViewModel = new EditPartViewModel { Name = typeViewModel.Name }; _contentDefinitionService.AddPart(new CreatePartViewModel { Name = partViewModel.Name }); _contentDefinitionService.AddPartToType(partViewModel.Name, typeViewModel.Name); } else { return(HttpNotFound()); } } viewModel.DisplayName = viewModel.DisplayName ?? String.Empty; viewModel.DisplayName = viewModel.DisplayName.Trim(); viewModel.Name = viewModel.Name ?? String.Empty; if (String.IsNullOrWhiteSpace(viewModel.DisplayName)) { ModelState.AddModelError("DisplayName", T("显示名称不能为空.").ToString()); } if (String.IsNullOrWhiteSpace(viewModel.Name)) { ModelState.AddModelError("Name", T("技术名称不能为空.").ToString()); } if (_contentDefinitionService.GetPart(partViewModel.Name).Fields.Any(t => String.Equals(t.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("Name", T("该字段已存在.").ToString()); } if (!String.IsNullOrWhiteSpace(viewModel.Name) && !viewModel.Name[0].IsLetter()) { ModelState.AddModelError("Name", T("技术名称必须以字母开头.").ToString()); } if (!String.Equals(viewModel.Name, viewModel.Name.ToSafeName(), StringComparison.OrdinalIgnoreCase)) { ModelState.AddModelError("Name", T("技术名称包含非法字符.").ToString()); } if (_contentDefinitionService.GetPart(partViewModel.Name).Fields.Any(t => String.Equals(t.DisplayName.Trim(), Convert.ToString(viewModel.DisplayName).Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("DisplayName", T("显示名称已存在.").ToString()); } if (!ModelState.IsValid) { viewModel.Part = partViewModel; viewModel.Fields = _contentDefinitionService.GetFields(); Services.TransactionManager.Cancel(); return(View(viewModel)); } try { _contentDefinitionService.AddFieldToPart(viewModel.Name, viewModel.DisplayName, viewModel.FieldTypeName, partViewModel.Name); } catch (Exception ex) { Services.Notifier.Information(T("字段 \"{0}\" 添加失败. {1}", viewModel.DisplayName, ex.Message)); Services.TransactionManager.Cancel(); return(AddFieldTo(id)); } Services.Notifier.Information(T("字段 \"{0}\" 添加成功.", viewModel.DisplayName)); if (typeViewModel != null) { return(RedirectToAction("Edit", new { id })); } return(RedirectToAction("EditPart", new { id })); }
public ActionResult CreateEditInfoPost(string id, AddFieldViewModel viewModel) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to edit a content part."))) { return(new HttpUnauthorizedResult()); } var entity = _contentMetadataService.GetDraftEntity(id); if (entity == null) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Content(string.Format("The entity with name \"{0}\" doesn't exist!", id))); } viewModel.DisplayName = string.IsNullOrWhiteSpace(viewModel.DisplayName) ? String.Empty : viewModel.DisplayName.Trim(); viewModel.Name = (viewModel.Name ?? viewModel.DisplayName).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 Technical Name can't be empty.").ToString()); } if (viewModel.Name.ToLower() == "id") { ModelState.AddModelError("Name", T("The Field Name can't be any case of 'Id'.").ToString()); } if (!_contentMetadataService.CheckFieldCreationValid(entity, viewModel.Name, viewModel.DisplayName)) { ModelState.AddModelError("Name", T("A field with the same name or displayName already exists.").ToString()); } try { _contentMetadataService.CreateField(entity, viewModel, this); if (!ModelState.IsValid) { Services.TransactionManager.Cancel(); Response.StatusCode = (int)HttpStatusCode.BadRequest; var errors = ModelState.Keys.SelectMany(k => ModelState[k].Errors) .Select(m => m.ErrorMessage).ToArray(); return(Content(string.Concat(errors))); } } catch (Exception ex) { var message = T("The \"{0}\" field was not added. {1}", viewModel.DisplayName, ex.Message); Services.Notifier.Information(message); Services.TransactionManager.Cancel(); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, message.ToString())); } Services.Notifier.Information(T("The \"{0}\" field has been added.", viewModel.DisplayName)); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public async Task <ActionResult> AddFieldToPOST(AddFieldViewModel viewModel, string id, string returnUrl = null) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(Forbid()); } var partViewModel = _contentDefinitionService.LoadPart(id); if (partViewModel == null) { return(NotFound()); } var partDefinition = partViewModel.PartDefinition; 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 (partDefinition.Fields.Any(f => String.Equals(f.DisplayName().Trim(), viewModel.DisplayName.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("DisplayName", S["A field with the same Display Name already exists."]); } if (String.IsNullOrWhiteSpace(viewModel.Name)) { ModelState.AddModelError("Name", S["The Technical Name can't be empty."]); } if (partDefinition.Fields.Any(f => String.Equals(f.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("Name", S["A field with the same Technical Name already exists."]); } 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 (!ModelState.IsValid) { viewModel.Part = partDefinition; viewModel.Fields = _contentDefinitionService.GetFields().Select(x => x.Name).OrderBy(x => x).ToList(); await _documentStore.CancelAsync(); ViewData["ReturnUrl"] = returnUrl; return(View(viewModel)); } _contentDefinitionService.AddFieldToPart(viewModel.Name, viewModel.DisplayName, viewModel.FieldTypeName, partDefinition.Name); await _notifier.SuccessAsync(H["The field \"{0}\" has been added.", viewModel.DisplayName]); if (!String.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl)) { return(this.Redirect(returnUrl, true)); } else { return(RedirectToAction(nameof(EditField), new { id, viewModel.Name })); } }
public ActionResult AddFieldToPOST(string id) { if (!Services.Authorizer.Authorize(Permissions.EditContentTypes, T("Not allowed to edit a content part."))) { return(new HttpUnauthorizedResult()); } var partViewModel = _contentDefinitionService.GetPart(id); var typeViewModel = _contentDefinitionService.GetType(id); if (partViewModel == null) { //id passed in might be that of a type w/ no implicit field if (typeViewModel != null) { partViewModel = new EditPartViewModel { Name = typeViewModel.Name }; _contentDefinitionService.AddPart(new CreatePartViewModel { Name = partViewModel.Name }); _contentDefinitionService.AddPartToType(partViewModel.Name, typeViewModel.Name); } else { return(HttpNotFound()); } } var viewModel = new AddFieldViewModel(); if (!TryUpdateModel(viewModel)) { Services.TransactionManager.Cancel(); return(AddFieldTo(id)); } try { _contentDefinitionService.AddFieldToPart(viewModel.DisplayName, viewModel.FieldTypeName, partViewModel.Name); } catch (Exception ex) { Services.Notifier.Information(T("The \"{0}\" field was not added. {1}", viewModel.DisplayName, ex.Message)); Services.TransactionManager.Cancel(); return(AddFieldTo(id)); } if (!ModelState.IsValid) { Services.TransactionManager.Cancel(); return(AddFieldTo(id)); } Services.Notifier.Information(T("The \"{0}\" field has been added.", viewModel.DisplayName)); if (typeViewModel != null) { return(RedirectToAction("Edit", new { id })); } return(RedirectToAction("EditPart", new { id })); }
public async Task <ActionResult> AddFieldToPOST(AddFieldViewModel viewModel, string id) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(Unauthorized()); } var partViewModel = _contentDefinitionService.GetPart(id); if (partViewModel == null) { return(NotFound()); } var partDefinition = partViewModel.PartDefinition; 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 name can't be empty."]); } if (String.IsNullOrWhiteSpace(viewModel.Name)) { ModelState.AddModelError("Name", S["The Technical Name can't be empty."]); } if (partDefinition.Fields.Any(t => String.Equals(t.Name.Trim(), viewModel.Name.Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("Name", S["A field with the same name already exists."]); } 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 (partDefinition.Fields.Any(t => String.Equals(t.DisplayName().Trim(), Convert.ToString(viewModel.DisplayName).Trim(), StringComparison.OrdinalIgnoreCase))) { ModelState.AddModelError("DisplayName", S["A field with the same Display Name already exists."]); } if (!ModelState.IsValid) { viewModel.Part = partDefinition; viewModel.Fields = _contentDefinitionService.GetFields().Select(x => x.Name).OrderBy(x => x).ToList(); _session.Cancel(); return(View(viewModel)); } _contentDefinitionService.AddFieldToPart(viewModel.Name, viewModel.DisplayName, viewModel.FieldTypeName, partDefinition.Name); _notifier.Success(T["The field \"{0}\" has been added.", viewModel.DisplayName]); return(RedirectToAction("EditField", new { id, viewModel.Name })); }
public AddFieldPage(int storeId, string storeName) { InitializeComponent(); BindingContext = _viewModel = new AddFieldViewModel(storeId, storeName); }