public bool Create(Domain.StringMap entity) { var result = true; using (UnitOfWork.Build(_stringMapRepository.DbContext)) { result = _stringMapRepository.Create(entity); //本地化标签 _localizedLabelService.Append(SolutionDefaults.DefaultSolutionId, entity.Name.IfEmpty(""), StringMapDefaults.ModuleName, "LocalizedName", entity.StringMapId) .Save(); } return(result); }
public bool Create(Domain.OptionSet entity) { Guard.NotNullOrEmpty(entity.Items, "items"); entity.SolutionId = SolutionDefaults.DefaultSolutionId;//组件属于默认解决方案 entity.OrganizationId = _appContext.OrganizationId; bool result = true; using (UnitOfWork.Build(_optionSetRepository.DbContext)) { result = _optionSetRepository.Create(entity); //solution component if (entity.IsPublic) { result = _solutionComponentService.Create(entity.SolutionId, entity.OptionSetId, OptionSetDefaults.ModuleName); } //存在明细项,不缓存, //_cacheService.SetEntity(entity); //details _optionSetDetailCreater.CreateMany(entity.Items); //本地化标签 _localizedLabelService.Append(entity.SolutionId, entity.Name.IfEmpty(""), OptionSetDefaults.ModuleName, "LocalizedName", entity.OptionSetId) .Append(entity.SolutionId, entity.Description.IfEmpty(""), OptionSetDefaults.ModuleName, "Description", entity.OptionSetId) .Save(); } return(result); }
private bool CreateCore(Domain.SystemForm entity, Action <Domain.SystemForm> createDependents) { if (entity.FormConfig.IsEmpty()) { return(false); } entity.OrganizationId = _appContext.OrganizationId; _formService.Init(entity); var result = true; using (UnitOfWork.Build(_systemFormRepository.DbContext)) { result = _systemFormRepository.Create(entity); //依赖项 createDependents?.Invoke(entity); //本地化标签 _localizedLabelService.Append(entity.SolutionId, entity.Name.IfEmpty(""), entity.FormType == (int)FormType.Dashboard ? DashBoardDefaults.ModuleName : FormDefaults.ModuleName, "LocalizedName", entity.SystemFormId) .Append(entity.SolutionId, entity.Description.IfEmpty(""), entity.FormType == (int)FormType.Dashboard ? DashBoardDefaults.ModuleName : FormDefaults.ModuleName, "Description", entity.SystemFormId) .Save(); _formService.UpdateLocalizedLabel(null); if (entity.FormType == (int)FormType.Dashboard) { //solution component result = _solutionComponentService.Create(entity.SolutionId, entity.SystemFormId, DashBoardDefaults.ModuleName); } //add to cache _cacheService.SetEntity(_systemFormRepository.FindById(entity.SystemFormId)); } return(result); }
public bool Create(Domain.Entity entity, params string[] defaultAttributeNames) { if (_entityRepository.Exists(x => x.Name == entity.Name)) { throw new XmsException(_loc["name_already_exists"]); } var solutionid = entity.SolutionId; //当前解决方案 entity.SolutionId = SolutionDefaults.DefaultSolutionId; //组件属于默认解决方案 var result = true; if (defaultAttributeNames.IsEmpty()) { //默认添加主键字段 defaultAttributeNames = new string[] { entity.Name + "Id" }; } else if (!defaultAttributeNames.Contains(entity.Name + "Id", StringComparer.InvariantCultureIgnoreCase)) { var namesList = defaultAttributeNames.ToList(); namesList.Add(entity.Name + "Id"); defaultAttributeNames = namesList.ToArray(); } var parentEntity = entity.ParentEntityId.HasValue ? _entityRepository.FindById(entity.ParentEntityId.Value) : null; var defaultAttributes = _defaultAttributeProvider.GetSysAttributes(entity).Where(x => defaultAttributeNames.Contains(x.Name, StringComparer.InvariantCultureIgnoreCase)).Distinct().ToList(); using (UnitOfWork.Build(_entityRepository.DbContext)) { result = _entityRepository.Create(entity, defaultAttributes, _defaultAttributeProvider.GetSysAttributeRelationShips(entity, defaultAttributes)); //创建默认字段 _attributeCreater.CreateDefaultAttributes(entity, defaultAttributeNames); //如果是子实体,则创建引用字段 if (parentEntity != null) { _attributeCreater.Create(new Domain.Attribute { Name = parentEntity.Name + "Id" , AttributeTypeName = AttributeTypeIds.LOOKUP , EntityId = entity.EntityId , EntityName = entity.Name , IsRequired = true , LocalizedName = parentEntity.LocalizedName , ReferencedEntityId = parentEntity.EntityId }); } //事件发布 _eventPublisher.Publish(new ObjectCreatedEvent <Domain.Entity>(entity)); //solution component _solutionComponentService.Create(solutionid, entity.EntityId, EntityDefaults.ModuleName); //本地化标签 _localizedLabelService.Append(entity.SolutionId, entity.LocalizedName.IfEmpty(""), EntityDefaults.ModuleName, "LocalizedName", entity.EntityId) .Append(entity.SolutionId, entity.Description.IfEmpty(""), EntityDefaults.ModuleName, "Description", entity.EntityId) .Save(); //add to cache _cacheService.SetEntity(entity); } return(result); }
private bool CreateCore(params Domain.OptionSetDetail[] entities) { Guard.NotEmpty(entities, nameof(entities)); bool result = false; using (UnitOfWork.Build(_optionSetDetailRepository.DbContext)) { result = _optionSetDetailRepository.CreateMany(entities); //本地化标签 foreach (var entity in entities) { _localizedLabelService.Append(SolutionDefaults.DefaultSolutionId, entity.Name.IfEmpty(""), OptionSetDefaults.ModuleName, "LocalizedName", entity.OptionSetDetailId); } _localizedLabelService.Save(); } return(result); }
public bool Create(Domain.WebResource entity) { var solutionid = entity.SolutionId; //当前解决方案 entity.SolutionId = SolutionDefaults.DefaultSolutionId; //组件属于默认解决方案 var result = true; using (UnitOfWork.Build(_webResourceRepository.DbContext)) { result = _webResourceRepository.Create(entity); //solution component _solutionComponentService.Create(solutionid, entity.WebResourceId, WebResourceDefaults.ModuleName); //本地化标签 _localizedLabelService.Append(entity.SolutionId, entity.Name.IfEmpty(""), WebResourceDefaults.ModuleName, "LocalizedName", entity.WebResourceId) .Append(entity.SolutionId, entity.Description.IfEmpty(""), WebResourceDefaults.ModuleName, "Description", entity.WebResourceId) .Save(); _cacheService.SetEntity(entity); } return(result); }
private bool CreateCore(Domain.QueryView entity, Action <Domain.QueryView> createDependents) { entity.SolutionId = SolutionDefaults.DefaultSolutionId;//组件属于默认解决方案 var result = true; using (UnitOfWork.Build(_queryViewRepository.DbContext)) { result = _queryViewRepository.Create(entity); //依赖项 createDependents(entity); //本地化标签 _localizedLabelService.Append(entity.SolutionId, entity.Name.IfEmpty(""), QueryViewDefaults.ModuleName, "LocalizedName", entity.QueryViewId) .Append(entity.SolutionId, entity.Description.IfEmpty(""), QueryViewDefaults.ModuleName, "Description", entity.QueryViewId) .Save(); //add to cache _cacheService.SetEntity(entity); } return(result); }
private bool CreateCore(params Domain.RibbonButton[] entities) { Guard.NotEmpty(entities, nameof(entities)); foreach (var entity in entities) { entity.SolutionId = SolutionDefaults.DefaultSolutionId;//组件属于默认解决方案 } var result = true; using (UnitOfWork.Build(_ribbonButtonRepository.DbContext)) { result = _ribbonButtonRepository.CreateMany(entities); _dependencyService.Create(entities); //本地化标签 foreach (var entity in entities) { _localizedLabelService.Append(entity.SolutionId, entity.Label.IfEmpty(""), RibbonButtonDefaults.ModuleName, "LocalizedName", entity.RibbonButtonId) .Append(entity.SolutionId, entity.Description.IfEmpty(""), RibbonButtonDefaults.ModuleName, "Description", entity.RibbonButtonId); } _localizedLabelService.Save(); } return(result); }
public void UpdateLocalizedLabel(Domain.SystemForm original) { //删除原有的 if (original != null) { DeleteOriginalLabels(original); } var attributeMetadatas = _attributeFinder.FindByEntityId(_entityid); var solutionId = SolutionDefaults.DefaultSolutionId;//组件属于默认解决方案 if (Form.Header != null && Form.Header.Rows.NotEmpty()) { //header foreach (var row in Form.Header.Rows) { foreach (var cell in row.Cells) { if (!cell.Id.Equals(Guid.Empty) && cell.Label.IsNotEmpty()) { if (cell.Control.ControlType == FormControlType.Standard || cell.Control.ControlType == FormControlType.Hidden || cell.Control.ControlType == FormControlType.Lookup || cell.Control.ControlType == FormControlType.OptionSet) { var attr = attributeMetadatas.Find(n => n.Name.IsCaseInsensitiveEqual(cell.Control.Name)); if (attr != null && !cell.Label.IsCaseInsensitiveEqual(attr.LocalizedName))//与字段显示名称不一致时 { _localizedLabelBatchBuilder.Append(solutionId, cell.Label, FormDefaults.ModuleName, "LayoutLabel", cell.Id); } } else { _localizedLabelBatchBuilder.Append(solutionId, cell.Label, FormDefaults.ModuleName, "LayoutLabel", cell.Id); } } } } } if (Form.NavGroups.NotEmpty()) { //navs foreach (var navg in Form.NavGroups) { if (!navg.Id.Equals(Guid.Empty) && navg.Label.IsNotEmpty()) { _localizedLabelBatchBuilder.Append(solutionId, navg.Label, FormDefaults.ModuleName, "LayoutLabel", navg.Id); } foreach (var item in navg.NavItems) { _localizedLabelBatchBuilder.Append(solutionId, item.Label, FormDefaults.ModuleName, "LayoutLabel", item.Id); } } } if (Form.Panels.NotEmpty()) { //tabs foreach (var tab in Form.Panels) { if (!tab.Id.Equals(Guid.Empty) && tab.Label.IsNotEmpty()) { _localizedLabelBatchBuilder.Append(solutionId, tab.Label, FormDefaults.ModuleName, "LayoutLabel", tab.Id); } foreach (var sec in tab.Sections) { if (!sec.Id.Equals(Guid.Empty) && sec.Label.IsNotEmpty()) { _localizedLabelBatchBuilder.Append(solutionId, sec.Label, FormDefaults.ModuleName, "LayoutLabel", sec.Id); } foreach (var row in sec.Rows) { foreach (var cell in row.Cells) { if (!cell.Id.Equals(Guid.Empty) && cell.Label.IsNotEmpty()) { if (cell.Control.ControlType == FormControlType.Standard || cell.Control.ControlType == FormControlType.Hidden || cell.Control.ControlType == FormControlType.Lookup || cell.Control.ControlType == FormControlType.OptionSet) { var attr = attributeMetadatas.Find(n => n.Name.IsCaseInsensitiveEqual(cell.Control.Name)); if (attr != null && !cell.Label.IsCaseInsensitiveEqual(attr.LocalizedName))//与字段显示名称不一致时 { _localizedLabelBatchBuilder.Append(solutionId, cell.Label, FormDefaults.ModuleName, "LayoutLabel", cell.Id); } } else { _localizedLabelBatchBuilder.Append(solutionId, cell.Label, FormDefaults.ModuleName, "LayoutLabel", cell.Id); } } } } } } if (Form.Footer != null && Form.Footer.Rows.NotEmpty()) { //footer foreach (var row in Form.Footer.Rows) { foreach (var cell in row.Cells) { if (!cell.Id.Equals(Guid.Empty) && cell.Label.IsNotEmpty()) { if (cell.Control.ControlType == FormControlType.Standard || cell.Control.ControlType == FormControlType.Hidden || cell.Control.ControlType == FormControlType.Lookup || cell.Control.ControlType == FormControlType.OptionSet) { var attr = attributeMetadatas.Find(n => n.Name.IsCaseInsensitiveEqual(cell.Control.Name)); if (attr != null && !cell.Label.IsCaseInsensitiveEqual(attr.LocalizedName))//与字段显示名称不一致时 { _localizedLabelBatchBuilder.Append(solutionId, cell.Label, FormDefaults.ModuleName, "LayoutLabel", cell.Id); } } else { _localizedLabelBatchBuilder.Append(solutionId, cell.Label, FormDefaults.ModuleName, "LayoutLabel", cell.Id); } } } } } } _localizedLabelBatchBuilder.Save(); }
public bool Create(Domain.Attribute entity) { //检查名称是否已存在 if (_attributeRepository.Exists(x => x.EntityId == entity.EntityId && x.Name == entity.Name)) { throw new XmsException(_loc["ATTRIBUTE_NAME_EXISTS"]); } var result = true; if (entity.DefaultValue.IsEmpty() && (entity.TypeIsBit() || entity.TypeIsDecimal() || entity.TypeIsFloat() || entity.TypeIsInt() || entity.TypeIsMoney() || entity.TypeIsSmallInt() || entity.TypeIsSmallMoney() || entity.TypeIsState() || entity.TypeIsStatus())) { entity.DefaultValue = "0"; } var parentEntity = _entityFinder.FindById(entity.EntityId); using (UnitOfWork.Build(_attributeRepository.DbContext)) { result = _attributeRepository.Create(entity); if (result) { //引用类型 if (entity.TypeIsLookUp() || entity.TypeIsOwner() || entity.TypeIsCustomer()) { var referencing = _entityFinder.FindById(entity.EntityId); var referenced = _attributeRepository.Find(x => x.EntityId == entity.ReferencedEntityId.Value && x.AttributeTypeName == AttributeTypeIds.PRIMARYKEY); var relationShip = new Domain.RelationShip { Name = "lk_" + referencing.Name + "_" + entity.Name, RelationshipType = RelationShipType.ManyToOne, ReferencingAttributeId = entity.AttributeId, ReferencingEntityId = entity.EntityId, ReferencedAttributeId = referenced.AttributeId, ReferencedEntityId = referenced.EntityId, CascadeLinkMask = parentEntity.ParentEntityId.HasValue ? 1 : 2, CascadeAssign = parentEntity.ParentEntityId.HasValue ? 1 : 4, CascadeDelete = parentEntity.ParentEntityId.HasValue ? 1 : 4, CascadeShare = parentEntity.ParentEntityId.HasValue ? 1 : 4, CascadeUnShare = parentEntity.ParentEntityId.HasValue ? 1 : 4, IsCustomizable = !parentEntity.ParentEntityId.HasValue }; _relationShipCreater.Create(relationShip); } //选项类型 else if (entity.TypeIsPickList()) { if (entity.OptionSet != null && !entity.OptionSet.IsPublic) { _optionSetCreater.Create(entity.OptionSet); } } //bit类型 else if (entity.TypeIsBit()) { _stringMapCreater.CreateMany(entity.PickLists); } //update db view _metadataService.AlterView(_entityFinder.FindById(entity.EntityId)); //依赖项 _dependencyService.Create(entity); //本地化标签 _localizedLabelService.Append(SolutionDefaults.DefaultSolutionId, entity.LocalizedName.IfEmpty(""), AttributeDefaults.ModuleName, "LocalizedName", entity.AttributeId) .Append(SolutionDefaults.DefaultSolutionId, entity.Description.IfEmpty(""), AttributeDefaults.ModuleName, "Description", entity.AttributeId) .Save(); //add to cache _cacheService.SetEntity(entity); } } return(result); }