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); }
public bool CreateDefaultAttributes(Domain.Entity entity, params string[] defaultAttributeNames) { var result = true; var attributes = _defaultAttributeProvider.GetSysAttributes(entity).Where(x => defaultAttributeNames.Contains(x.Name, StringComparer.InvariantCultureIgnoreCase)).ToList(); using (UnitOfWork.Build(_attributeRepository.DbContext)) { result = _attributeRepository.CreateMany(attributes); //新建字段选项 var stateCodeAttr = attributes.Find(n => n.Name.IsCaseInsensitiveEqual("statecode")); if (stateCodeAttr != null) { result = _stringMapCreater.CreateMany(stateCodeAttr.PickLists); } var statusCodeAttr = attributes.Find(n => n.Name.IsCaseInsensitiveEqual("statuscode")); if (statusCodeAttr != null) { _optionSetCreater.Create(statusCodeAttr.OptionSet); } //创建关系 result = _relationShipCreater.CreateMany(_defaultAttributeProvider.GetSysAttributeRelationShips(entity, attributes)); //attribute localization foreach (var attr in attributes) { var label = attr.TypeIsPrimaryKey() ? entity.LocalizedName : _loc["entity_sys_" + attr.Name]; _localizedLabelService.Append(entity.SolutionId, label, AttributeDefaults.ModuleName, "LocalizedName", attr.AttributeId) .Append(entity.SolutionId, label, AttributeDefaults.ModuleName, "Description", attr.AttributeId); } _localizedLabelService.Save(); //add to cache foreach (var attr in attributes) { _cacheService.SetEntity(attr); } } return(result); }
public IActionResult GetSystemAttributes(EntityMaskEnum entityMask) { return(JOk(_defaultAttributeProvider.GetSysAttributes(new Schema.Domain.Entity { BusinessFlowEnabled = true, WorkFlowEnabled = true, EntityMask = entityMask }))); }
public void CreateView(Domain.Entity entity) { var defaultAttributes = _defaultAttributeProvider.GetSysAttributes(entity); _metadataProvider.AlterView(entity, defaultAttributes, _defaultAttributeProvider.GetSysAttributeRelationShips(entity, defaultAttributes)); }
public bool CreateDefaultView(Schema.Domain.Entity entity) { var(DefaultView, Dependents) = _defaultQueryViewProvider.Get(entity, _defaultAttributeProvider.GetSysAttributes(entity)); return(this.Create(DefaultView)); }
/// <summary> /// 生成默认表单 /// </summary> /// <param name="entity"></param> /// <returns></returns> public (Domain.SystemForm DefaultForm, List <Dependency.Domain.Dependency> Dependents) Get(Schema.Domain.Entity entity) { Domain.SystemForm form = new Domain.SystemForm { CanBeDeleted = false, CreatedBy = entity.CreatedBy, CreatedOn = DateTime.Now, Description = _loc["form_default"], EntityId = entity.EntityId, FormType = (int)FormType.Main, Name = entity.LocalizedName, StateCode = RecordState.Enabled, SystemFormId = Guid.NewGuid(), IsDefault = true }; var nameAttribute = _defaultAttributeProvider.GetSysAttributes(entity).Find(x => x.Name.IsCaseInsensitiveEqual("name")); FormDescriptor formObj = new FormDescriptor(); formObj.Name = entity.LocalizedName; formObj.IsShowNav = false; formObj.Panels = new List <PanelDescriptor> { new PanelDescriptor() { Name = _loc["form_information"] , Label = _loc["form_information"] , IsExpanded = true , IsShowLabel = true , IsVisible = true , Sections = new List <SectionDescriptor>() { new SectionDescriptor() { IsShowLabel = false , IsVisible = true , Label = _loc["form_information"] , Columns = 2 , Rows = new List <RowDescriptor>() { new RowDescriptor() { IsVisible = true , Cells = new List <CellDescriptor>() { new CellDescriptor() { IsShowLabel = true, IsVisible = true, Label = nameAttribute.LocalizedName, Control = new ControlDescriptor() { EntityName = entity.Name, Name = "name", ControlType = FormControlType.Standard } } , new CellDescriptor() { Control = new ControlDescriptor() { ControlType = FormControlType.None } } } } } } } } }; form.FormConfig = formObj.SerializeToJson(false); var dp = new Dependency.Domain.Dependency(); //dp.DependentComponentType = DependencyComponentTypes.Get(FormDefaults.ModuleName); dp.DependentObjectId = form.SystemFormId; //dp.RequiredComponentType = DependencyComponentTypes.Get(AttributeDefaults.ModuleName); dp.RequiredObjectId = nameAttribute.AttributeId; var dependents = new List <Dependency.Domain.Dependency>() { dp }; return(form, dependents); }