public IActionResult Delete(DeleteEntityRecordModel model) { if (model.RecordId.IsEmpty()) { return(NotSpecifiedRecord()); } Entity entityMetadata = null; if (model.EntityName.IsNotEmpty()) { entityMetadata = _entityFinder.FindByName(model.EntityName); } else { entityMetadata = _entityFinder.FindById(model.EntityId); } if (entityMetadata == null) { return(NotFound()); } return(_dataDeleter.Delete(entityMetadata.Name, model.RecordId).DeleteResult(T)); }
public IActionResult EditFilterRule(Guid id) { EditFilterRuleModel model = new EditFilterRuleModel(); if (!id.Equals(Guid.Empty)) { var entity = _filterRuleFinder.FindById(id); if (entity != null) { entity.CopyTo(model); model.FilterRuleId = id; model.Name = entity.Name; model.EventName = entity.EventName; model.EntityId = entity.EntityId; model.ToolTip = entity.ToolTip; model.StateCode = entity.StateCode; model.EntityMeta = _entityFinder.FindById(entity.EntityId); return(View(model)); } } return(NotFound()); }
public IActionResult Import(Guid entityId, DialogModel dm) { var entityMetadata = _entityFinder.FindById(entityId); if (entityMetadata == null) { return(NotFound()); } ImportModel model = new ImportModel { EntityId = entityId , EntityName = entityMetadata.Name , DataFileName = _sessionService.GetValue("importfile") , DuplicateDetection = 1 }; ViewBag.dialogmodel = dm; return(View(model)); }
public IActionResult WorkFlowInstanceDetail(Guid entityid, Guid recordid) { var instances = _workFlowInstanceService.Query(n => n .Where(f => f.EntityId == entityid && f.ObjectId == recordid) .Sort(s => s.SortDescending(f => f.CreatedOn)) ); if (instances.IsEmpty()) { return(NotFound()); } var entityMeta = _entityFinder.FindById(entityid); if (entityMeta == null) { return(NotFound()); } foreach (var instance in instances) { var steps = _workFlowProcessFinder.Query(n => n .Where(f => f.WorkFlowInstanceId == instance.WorkFlowInstanceId && f.StateCode != WorkFlowProcessState.Disabled) .Sort(s => s.SortAscending(f => f.StepOrder)).Sort(s => s.SortAscending(f => f.StateCode))); instance.Steps = steps; } WorkFlowInstanceDetailModel model = new WorkFlowInstanceDetailModel(); model.Items = instances; var workFlowId = instances.First().WorkFlowId; model.FlowInfo = _workFlowFinder.FindById(workFlowId); var allSteps = _workFlowStepService.Query(n => n.Where(f => f.WorkFlowId == workFlowId).Sort(s => s.SortAscending(f => f.StepOrder))); model.Steps = allSteps; return(View(model)); }
public IActionResult StartWorkFlow(Guid entityId, Guid recordId) { StartWorkFlowModel model = new StartWorkFlowModel { EntityId = entityId, RecordId = recordId }; //实体元数据 var entityMetas = _entityFinder.FindById(model.EntityId); //查找记录 var entity = _dataFinder.RetrieveById(entityMetas.Name, model.RecordId); if (entity.GetIntValue("ProcessState") == (int)WorkFlowProcessState.Processing) { return(JError(T["workflow_processing_notallowtwice"])); } if (entity.GetIntValue("ProcessState") == (int)WorkFlowProcessState.Passed) { return(JError(T["workflow_stop_notallowtwice"])); } if (entity.GetIntValue("ProcessState", -1) != -1 && (entity.GetIntValue("ProcessState") == (int)WorkFlowProcessState.Waiting || entity.GetIntValue("ProcessState") == (int)WorkFlowProcessState.Disabled)) { return(JError(T["workflow_state_notallowtwice"])); } //找到审批流程 var wfs = _workFlowFinder.QueryAuthorized(model.EntityId, FlowType.Approval); if (wfs.IsEmpty()) { return(NotFound()); } model.WorkFlows = wfs; return(View($"~/Views/Flow/{WebContext.ActionName}.cshtml", model)); }
private bool DeleteCore(IEnumerable <Domain.Attribute> deleteds, Func <Domain.Attribute, bool> validation) { Guard.NotEmpty(deleteds, nameof(deleteds)); var result = true; if (validation != null) { foreach (var deleted in deleteds) { result = validation?.Invoke(deleted) ?? true; } } if (result) { var ids = deleteds.Select(x => x.AttributeId).ToArray(); using (UnitOfWork.Build(_attributeRepository.DbContext)) { foreach (var deleted in deleteds) { result = _attributeRepository.Delete(deleted); //删除依赖项 _dependencyService.Delete(deleted.AttributeId); //remove from cache _cacheService.RemoveEntity(deleted); //localization _localizedLabelService.DeleteByObject(deleted.AttributeId); _eventPublisher.Publish(new ObjectDeletedEvent <Domain.Attribute>(AttributeDefaults.ModuleName, deleted)); } //cascade delete _cascadeDeletes?.ToList().ForEach((x) => { x.CascadeDelete(deleteds.ToArray()); }); //update db view _metadataService.AlterView(_entityFinder.FindById(deleteds.First().EntityId)); } } return(result); }
public IActionResult Index(EntityMapModel model) { if (model.EntityId.Equals(Guid.Empty)) { return(NotFound()); } var entity = _entityFinder.FindById(model.EntityId); if (entity == null) { return(NotFound()); } model.Entity = entity; if (!model.LoadData) { return(DynamicResult(model)); } FilterContainer <EntityMap> filter = FilterContainerBuilder.Build <EntityMap>(); filter.And(n => n.TargetEntityId == model.EntityId); if (model.GetAll) { model.Page = 1; model.PageSize = WebContext.PlatformSettings.MaxFetchRecords; } else if (!model.PageSizeBySeted && CurrentUser.UserSettings.PagingLimit > 0) { model.PageSize = CurrentUser.UserSettings.PagingLimit; } model.PageSize = model.PageSize > WebContext.PlatformSettings.MaxFetchRecords ? WebContext.PlatformSettings.MaxFetchRecords : model.PageSize; PagedList <EntityMap> result = _entityMapFinder.QueryPaged(x => x .Page(model.Page, model.PageSize) .Where(filter) .Sort(n => n.OnFile(model.SortBy).ByDirection(model.SortDirection)) ); model.Items = result.Items; model.TotalItems = result.TotalItems; model.SolutionId = SolutionId.Value; return(DynamicResult(model)); }
public IActionResult GetCompleteInfo(EntityFormModel args) { string nonePermissionFields = null, form = null, records = null; if (args.EntityId.Equals(Guid.Empty) && args.EntityName.IsEmpty()) { return(NotFound()); } var entity = args.EntityId.Equals(Guid.Empty) ? _entityFinder.FindByName(args.EntityName) : _entityFinder.FindById(args.EntityId); if (entity == null) { return(NotFound()); } args.EntityId = entity.EntityId; args.EntityName = entity.Name; EditRecordModel m = new EditRecordModel { EntityMetaData = entity, EntityId = args.EntityId, RelationShipName = args.RelationShipName, ReferencedRecordId = args.ReferencedRecordId }; if (args.RecordId.HasValue && !args.RecordId.Value.Equals(Guid.Empty)) { var record = _dataFinder.RetrieveById(entity.Name, args.RecordId.Value); if (record == null || record.Count == 0) { return(NotFound()); } var fileAttributes = _attributeFinder.FindByEntityId(entity.EntityId).Where(n => n.DataFormat.IsCaseInsensitiveEqual("fileupload")); foreach (var item in fileAttributes) { if (record.GetStringValue(item.Name).IsNotEmpty()) { record[item.Name] = string.Empty; } else { record.Remove(item.Name); } } m.Entity = record; m.RecordId = args.RecordId; m.FormState = FormState.Update; if (m.Entity.GetIntValue("statecode", -1) == 0) { m.FormState = FormState.Disabled; //model.ReadOnly = true; } } else if (args.CopyId.HasValue && !args.CopyId.Value.Equals(Guid.Empty)) { var record = _dataFinder.RetrieveById(entity.Name, args.CopyId.Value); if (record == null || record.Count == 0) { return(NotFound()); } var fileAttributes = _attributeFinder.FindByEntityId(entity.EntityId).Where(n => n.DataFormat.IsCaseInsensitiveEqual("fileupload")); foreach (var item in fileAttributes) { record.Remove(item.Name); } record.RemoveKeys(AttributeDefaults.SystemAttributes); m.Entity = record; //m.RecordId = model.RecordId; m.FormState = FormState.Create; } else { //ViewData["record"] = "{}"; m.FormState = FormState.Create; } m.ReadOnly = args.ReadOnly; var isCreate = !args.RecordId.HasValue || args.RecordId.Value.Equals(Guid.Empty); SystemForm formEntity = null; //workflow if (!isCreate && m.EntityMetaData.WorkFlowEnabled && m.Entity.GetGuidValue("workflowid").Equals(Guid.Empty)) { var processState = m.Entity.GetIntValue("processstate", -1); if (processState == (int)WorkFlowProcessState.Processing)// || processState == (int)WorkFlowProcessState.Passed) { m.ReadOnly = true; m.FormState = FormState.ReadOnly; var instances = _workFlowInstanceService.Query(n => n.Take(1).Where(f => f.EntityId == m.EntityId.Value && f.ObjectId == m.RecordId.Value).Sort(s => s.SortDescending(f => f.CreatedOn))); WorkFlowInstance instance = null; if (instances.NotEmpty()) { instance = instances.First(); } if (instance != null) { var processInfo = _workFlowProcessFinder.GetCurrentStep(instance.WorkFlowInstanceId, CurrentUser.SystemUserId); if (processInfo != null) { if (!processInfo.FormId.Equals(Guid.Empty)) { formEntity = _systemFormFinder.FindById(processInfo.FormId); } } } } m.WorkFlowProcessState = processState; } if (formEntity == null) { if (args.FormId.HasValue && !args.FormId.Value.Equals(Guid.Empty)) { formEntity = _systemFormFinder.FindById(args.FormId.Value); if (formEntity.StateCode != RecordState.Enabled) { formEntity = null; } } else { //获取实体默认表单 formEntity = _systemFormFinder.FindEntityDefaultForm(args.EntityId); } } if (formEntity == null) { return(JError(T["notfound_defaultform"])); } m.FormInfo = formEntity; m.FormId = formEntity.SystemFormId; FormBuilder formBuilder = new FormBuilder(formEntity.FormConfig); _formService.Init(formEntity); //表单可用状态 if (!isCreate && m.FormState != FormState.Disabled && formBuilder.Form.FormRules.NotEmpty()) { if (_systemFormStatusSetter.IsDisabled(formBuilder.Form.FormRules, m.Entity)) { m.FormState = FormState.Disabled; } } //获取所有字段信息 m.AttributeList = _formService.AttributeMetaDatas; //获取字段权限 if (!CurrentUser.IsSuperAdmin && m.AttributeList.Count(n => n.AuthorizationEnabled) > 0) { var securityFields = m.AttributeList.Where(n => n.AuthorizationEnabled).Select(f => f.AttributeId)?.ToList(); if (securityFields.NotEmpty()) { //无权限的字段 var noneRead = _systemUserPermissionService.GetNoneReadFields(CurrentUser.SystemUserId, securityFields); var noneEdit = _systemUserPermissionService.GetNoneEditFields(CurrentUser.SystemUserId, securityFields); //移除无读取权限的字段内容 if (m.Entity.NotEmpty()) { foreach (var item in noneRead) { m.Entity.Remove(m.AttributeList.Find(n => n.AttributeId == item).Name); } } var obj = new { noneread = noneRead, noneedit = noneEdit }; nonePermissionFields = obj.SerializeToJson(); } } else { nonePermissionFields = "[]"; } var _form = formBuilder.Form; m.Form = _form; form = _formService.Form.SerializeToJson(false); //buttons var buttons = _ribbonbuttonFinder.Find(m.EntityId.Value, RibbonButtonArea.Form); if (formEntity.IsCustomButton && formEntity.CustomButtons.IsNotEmpty()) { List <Guid> buttonid = new List <Guid>(); buttonid = buttonid.DeserializeFromJson(formEntity.CustomButtons); buttons.RemoveAll(x => !buttonid.Contains(x.RibbonButtonId)); } if (buttons.NotEmpty()) { buttons = buttons.OrderBy(x => x.DisplayOrder).ToList(); m.RibbonButtons = buttons; _ribbonButtonStatusSetter.Set(m.RibbonButtons, m.FormState, m.Entity); } if (isCreate) { var rep = _roleObjectAccessEntityPermissionService.FindUserPermission(m.EntityMetaData.Name, CurrentUser.LoginName, AccessRightValue.Create); m.HasBasePermission = rep != null && rep.AccessRightsMask != EntityPermissionDepth.None; } else { var rep = _roleObjectAccessEntityPermissionService.FindUserPermission(m.EntityMetaData.Name, CurrentUser.LoginName, AccessRightValue.Update); m.HasBasePermission = rep != null && rep.AccessRightsMask != EntityPermissionDepth.None; } m.SnRule = _serialNumberRuleFinder.FindByEntityId(args.EntityId); if (m.SnRule != null && m.Entity.NotEmpty() && args.CopyId.HasValue) { m.Entity.SetAttributeValue(m.SnRule.AttributeName, null); } records = m.Entity.SerializeToJson(); m.StageId = args.StageId; m.BusinessFlowId = args.BusinessFlowId; m.BusinessFlowInstanceId = args.BusinessFlowInstanceId; return(JOk(new { EditRecord = m, NonePermissionFields = nonePermissionFields, Form = form, Record = records })); }
public async Task <IActionResult> Post([FromForm] SaveDataModel model) { if (model.EntityId.Equals(Guid.Empty)) { return(NotFound()); } var entityMetaData = _entityFinder.FindById(model.EntityId); if (entityMetaData == null) { return(NotFound()); } AggregateRoot aggregateRoot = new AggregateRoot(); var attributeMetaDatas = _attributeFinder.FindByEntityId(model.EntityId); bool isNew = !(model.RecordId.HasValue && !model.RecordId.Value.Equals(Guid.Empty)); var thisId = Guid.Empty; try { Core.Data.Entity entity = new Core.Data.Entity(entityMetaData.Name); dynamic headData = JObject.Parse(model.Data); foreach (JProperty p in headData) { var attr = attributeMetaDatas.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name)); if (attr != null && p.Value != null) { entity.SetAttributeValue(p.Name.ToString().ToLower(), entity.WrapAttributeValue(_entityFinder, attr, p.Value.ToString())); } } if (isNew) { thisId = Guid.NewGuid(); if (model.RelationShipName.IsNotEmpty() && model.ReferencedRecordId.HasValue)//如果存在关联关系 { var relationShipMetas = _relationShipFinder.FindByName(model.RelationShipName); if (null != relationShipMetas && relationShipMetas.ReferencingEntityId == model.EntityId && entity.GetStringValue(relationShipMetas.ReferencingAttributeName).IsEmpty()) { //设置当前记录关联字段的值 entity.SetAttributeValue(relationShipMetas.ReferencingAttributeName, new EntityReference(relationShipMetas.ReferencedEntityName, model.ReferencedRecordId.Value)); } } if (!model.StageId.Equals(Guid.Empty))//业务流程的阶段 { entity.SetAttributeValue("StageId", model.StageId); } //thisId = _dataCreater.Create(entity); if (!model.StageId.Equals(Guid.Empty))//业务流程的阶段 { _businessProcessFlowInstanceUpdater.UpdateForward(model.BusinessFlowId, model.BusinessFlowInstanceId, model.StageId, thisId); } } else { thisId = model.RecordId.Value; entity.SetIdValue(model.RecordId.Value); } aggregateRoot.MainEntity = entity; aggregateRoot.ChildEntities = new List <RefEntity>(); //单据体 if (model.Child.IsNotEmpty()) { var childs = JArray.Parse(model.Child.UrlDecode()); if (childs.Count > 0) { List <Core.Data.Entity> childEntities = new List <Core.Data.Entity>(); List <string> entityNames = new List <string>(); foreach (var c in childs) { dynamic root = JObject.Parse(c.ToString()); string name = root.name, relationshipname = root.relationshipname, refname = string.Empty; OperationTypeEnum?entitystatus = root.entitystatus; if (!entityNames.Exists(n => n.IsCaseInsensitiveEqual(name))) { entityNames.Add(name); } var data = root.data; var childAttributes = _attributeFinder.FindByEntityName(name); if (relationshipname.IsNotEmpty()) { var relationShipMetas = _relationShipFinder.FindByName(relationshipname); if (null != relationShipMetas && relationShipMetas.ReferencedEntityId == model.EntityId) { refname = relationShipMetas.ReferencingAttributeName; } } Core.Data.Entity detail = new Core.Data.Entity(name); RefEntity refEntity = new RefEntity() { Name = name, Relationshipname = relationshipname, Entityid = model.EntityId, Entitystatus = entitystatus }; foreach (JProperty p in data) { var attr = childAttributes.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name)); if (attr != null && p.Value != null) { detail.SetAttributeValue(p.Name.ToString().ToLower(), detail.WrapAttributeValue(_entityFinder, attr, p.Value.ToString())); } refEntity.Entity = detail; } //关联主记录ID if (refname.IsNotEmpty()) { detail.SetAttributeValue(refname, new EntityReference(entityMetaData.Name, thisId)); } aggregateRoot.ChildEntities.Add(refEntity); } } } //附件保存 var files = Request.Form.Files; if (files.Count > 0) { var result = await _attachmentCreater.CreateManyAsync(model.EntityId, thisId, files.ToList()).ConfigureAwait(false); for (int i = 0; i < files.Count; i++) { var attr = attributeMetaDatas.Find(n => n.Name.IsCaseInsensitiveEqual(files[i].Name)); if (attr != null) { var etAttachement = result.Where(x => x["Name"].ToString().IsCaseInsensitiveEqual(files[i].FileName)).First(); if (etAttachement != null) { entity.SetAttributeValue(files[i].Name, entity.WrapAttributeValue(_entityFinder, attr, etAttachement["CDNPath"].ToString())); } } } } if (isNew) { thisId = _aggCreater.Create(aggregateRoot, thisId, model.FormId); } else { _aggUpdater.Update(aggregateRoot, model.FormId); } } catch (Exception ex) { return(JError(ex.InnerException != null ? ex.InnerException.Message : ex.Message)); } if (isNew) { return(CreateSuccess(new { id = thisId })); } return(UpdateSuccess(new { id = thisId })); }
public bool UpdateBack(Guid workFlowId, Guid instanceId, Guid processStageId, Guid recordId) { var bpfInstance = _businessProcessFlowInstanceRepository.Find(n => n.BusinessProcessFlowInstanceId == instanceId && n.WorkFlowId == workFlowId); if (bpfInstance == null) { return(false); } var stages = _processStageService.Query(n => n .Where(f => f.WorkFlowId == workFlowId) .Sort(s => s.SortAscending(f => f.StageOrder))); var currentStage = stages.Find(n => n.ProcessStageId == processStageId); var entityIds = stages.Select(n => n.EntityId).Distinct().ToList(); int entityIndex = entityIds.FindIndex(n => n.Equals(currentStage.EntityId)) + 1; //var _bpfService = new BusinessProcessFlowInstanceService(User); var originalStage = stages.Find(n => n.ProcessStageId == bpfInstance.ProcessStageId); //var _organizationServiceProxy = new SDK.OrganizationServiceProxy(User); var eidMeta = _entityFinder.FindById(originalStage.EntityId); var filter = new Dictionary <string, object>(); if (entityIndex == 1) { this.Update(n => n .Set(f => f.ProcessStageId, currentStage.ProcessStageId) .Set(f => f.ProcessEntityId, currentStage.EntityId) .Set(f => f.Entity2Id, null) .Set(f => f.Entity3Id, null) .Set(f => f.Entity4Id, null) .Set(f => f.Entity5Id, null) .Where(w => w.BusinessProcessFlowInstanceId == bpfInstance.BusinessProcessFlowInstanceId) ); filter.Add(eidMeta.Name + "id", bpfInstance.Entity2Id); } else if (entityIndex == 2) { this.Update(n => n .Set(f => f.ProcessStageId, currentStage.ProcessStageId) .Set(f => f.ProcessEntityId, currentStage.EntityId) .Set(f => f.Entity3Id, null) .Set(f => f.Entity4Id, null) .Set(f => f.Entity5Id, null) .Where(w => w.BusinessProcessFlowInstanceId == bpfInstance.BusinessProcessFlowInstanceId) ); filter.Add(eidMeta.Name + "id", bpfInstance.Entity3Id); } else if (entityIndex == 3) { this.Update(n => n .Set(f => f.ProcessStageId, currentStage.ProcessStageId) .Set(f => f.ProcessEntityId, currentStage.EntityId) .Set(f => f.Entity4Id, null) .Set(f => f.Entity5Id, null) .Where(w => w.BusinessProcessFlowInstanceId == bpfInstance.BusinessProcessFlowInstanceId) ); filter.Add(eidMeta.Name + "id", bpfInstance.Entity4Id); } else if (entityIndex == 4) { this.Update(n => n .Set(f => f.ProcessStageId, currentStage.ProcessStageId) .Set(f => f.ProcessEntityId, currentStage.EntityId) .Set(f => f.Entity5Id, null) .Where(w => w.BusinessProcessFlowInstanceId == bpfInstance.BusinessProcessFlowInstanceId) ); filter.Add(eidMeta.Name + "id", bpfInstance.Entity5Id); } if (!originalStage.EntityId.Equals(currentStage.EntityId)) { //更新原阶段对应的实体记录的阶段 var originalData = _dataFinder.RetrieveByAttribute(eidMeta.Name, filter); if (originalData.NotEmpty()) { var updOgnData = new Entity(originalData.Name); updOgnData.SetIdValue(originalData.GetIdValue()); updOgnData.SetAttributeValue("stageid", null); _dataUpdater.Update(updOgnData); } } return(true); }
public IActionResult Post(SaveDataModel model) { if (model.EntityId.Equals(Guid.Empty)) { return(NotFound()); } var entityMetaData = _entityFinder.FindById(model.EntityId); if (entityMetaData == null) { return(NotFound()); } var attributeMetaDatas = _attributeFinder.FindByEntityId(model.EntityId); bool isNew = !(model.RecordId.HasValue && !model.RecordId.Value.Equals(Guid.Empty)); var thisId = Guid.Empty; try { Core.Data.Entity entity = new Core.Data.Entity(entityMetaData.Name); dynamic headData = JObject.Parse(model.Data); foreach (JProperty p in headData) { var attr = attributeMetaDatas.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name)); if (attr != null && p.Value != null) { entity.SetAttributeValue(p.Name.ToString().ToLower(), entity.WrapAttributeValue(_entityFinder, attr, p.Value.ToString())); } } if (isNew) { if (model.RelationShipName.IsNotEmpty() && model.ReferencedRecordId.HasValue)//如果存在关联关系 { var relationShipMetas = _relationShipFinder.FindByName(model.RelationShipName); if (null != relationShipMetas && relationShipMetas.ReferencingEntityId == model.EntityId && entity.GetStringValue(relationShipMetas.ReferencingAttributeName).IsEmpty()) { //设置当前记录关联字段的值 entity.SetAttributeValue(relationShipMetas.ReferencingAttributeName, new EntityReference(relationShipMetas.ReferencedEntityName, model.ReferencedRecordId.Value)); } } if (!model.StageId.Equals(Guid.Empty))//业务流程的阶段 { entity.SetAttributeValue("StageId", model.StageId); } thisId = _dataCreater.Create(entity); if (!model.StageId.Equals(Guid.Empty))//业务流程的阶段 { _businessProcessFlowInstanceUpdater.UpdateForward(model.BusinessFlowId, model.BusinessFlowInstanceId, model.StageId, thisId); } } else { thisId = model.RecordId.Value; entity.SetIdValue(model.RecordId.Value); _dataUpdater.Update(entity); } //单据体 if (model.Child.IsNotEmpty()) { var childs = JArray.Parse(model.Child.UrlDecode()); if (childs.Count > 0) { List <Core.Data.Entity> childEntities = new List <Core.Data.Entity>(); List <string> entityNames = new List <string>(); foreach (var c in childs) { dynamic root = JObject.Parse(c.ToString()); string name = root.name, relationshipname = root.relationshipname, refname = string.Empty; if (!entityNames.Exists(n => n.IsCaseInsensitiveEqual(name))) { entityNames.Add(name); } var data = root.data; var childAttributes = _attributeFinder.FindByEntityName(name); if (relationshipname.IsNotEmpty()) { var relationShipMetas = _relationShipFinder.FindByName(relationshipname); if (null != relationShipMetas && relationShipMetas.ReferencedEntityId == model.EntityId) { refname = relationShipMetas.ReferencingAttributeName; } } Core.Data.Entity detail = new Core.Data.Entity(name); foreach (JProperty p in data) { var attr = childAttributes.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name)); if (attr != null && p.Value != null) { detail.SetAttributeValue(p.Name.ToString().ToLower(), detail.WrapAttributeValue(_entityFinder, attr, p.Value.ToString())); } } //关联主记录ID if (refname.IsNotEmpty()) { detail.SetAttributeValue(refname, new EntityReference(entityMetaData.Name, thisId)); } childEntities.Add(detail); } //批量创建记录 if (childEntities.NotEmpty()) { foreach (var item in entityNames) { var items = childEntities.Where(n => n.Name.IsCaseInsensitiveEqual(item)).ToList(); var creatingRecords = items.Where(n => n.Name.IsCaseInsensitiveEqual(item) && n.GetIdValue().Equals(Guid.Empty)).ToList(); if (creatingRecords.NotEmpty()) { _dataCreater.CreateMany(creatingRecords); } if (!isNew) { foreach (var updItem in items.Where(n => n.Name.IsCaseInsensitiveEqual(item) && !n.GetIdValue().Equals(Guid.Empty))) { _dataUpdater.Update(updItem); } } } } } } } catch (Exception ex) { return(JError(ex.InnerException != null ? ex.InnerException.Message : ex.Message)); } if (isNew) { return(CreateSuccess(new { id = thisId })); } return(UpdateSuccess(new { id = thisId })); }
public IActionResult ForwardAndAppend(Guid entityid, Guid referencedrecordid, Guid workflowid, Guid stageid, Guid?instanceId, string relationshipname) { if (entityid.Equals(Guid.Empty) || referencedrecordid.Equals(Guid.Empty) || workflowid.Equals(Guid.Empty) || stageid.Equals(Guid.Empty)) { return(JError(T["parameter_error"])); } var entityMeta = _entityFinder.FindById(entityid); if (entityMeta == null) { return(NotFound()); } var flowInfo = _workFlowFinder.Find(n => n.WorkFlowId == workflowid); if (flowInfo == null) { return(NotFound()); } var stages = _processStageService.Query(n => n .Where(f => f.WorkFlowId == flowInfo.WorkFlowId) .Sort(s => s.SortAscending(f => f.StageOrder))); var currentStage = stages.Find(n => n.ProcessStageId == stageid); var prevStage = stages.Find(n => n.StageOrder == currentStage.StageOrder - 1); if (currentStage.EntityId.Equals(prevStage.EntityId)) { return(JError(T["parameter_error"])); } BusinessProcessFlowInstance bpfInstance = null; if (instanceId.HasValue && !instanceId.Value.Equals(Guid.Empty)) { bpfInstance = _businessProcessFlowInstanceService.Find(n => n.BusinessProcessFlowInstanceId == instanceId && n.WorkFlowId == workflowid); if (bpfInstance == null) { return(NotFound()); } } if (bpfInstance == null) { instanceId = Guid.NewGuid(); bpfInstance = new BusinessProcessFlowInstance(); bpfInstance.BusinessProcessFlowInstanceId = instanceId.Value; bpfInstance.WorkFlowId = workflowid; bpfInstance.ProcessStageId = stages.First().ProcessStageId; bpfInstance.Entity1Id = referencedrecordid; bpfInstance.ProcessEntityId = entityid; _businessProcessFlowInstanceService.Create(bpfInstance); } //是否存在单据转换规则 var entityMap = _entityMapFinder.Find(prevStage.EntityId, entityid); if (entityMap == null) { return(JOk(new { EntityId = entityid , StageId = stageid , BusinessFlowId = workflowid , BusinessFlowInstanceId = instanceId.Value , RelationShipName = relationshipname , ReferencedRecordId = referencedrecordid })); } var recordid = _dataMapper.Create(prevStage.EntityId, currentStage.EntityId, referencedrecordid); _businessProcessFlowInstanceUpdater.UpdateForward(workflowid, instanceId.Value, stageid, recordid); //更新当前记录的业务阶段 var updData = new Entity(entityMeta.Name); updData.SetIdValue(recordid); updData.SetAttributeValue("stageid", stageid); _dataUpdater.Update(updData); return(JOk(new { EntityId = entityid , RecordId = recordid , BusinessFlowId = workflowid , BusinessFlowInstanceId = instanceId.Value })); }
public IActionResult BusinessProcess([FromBody] BusinessProcessArgsModel args) { if (args.EntityId.Equals(Guid.Empty) || args.RecordId.Equals(Guid.Empty)) { return(JError(T["parameter_error"])); } var entityMeta = _entityFinder.FindById(args.EntityId); if (entityMeta == null) { return(NotFound()); } if (!entityMeta.BusinessFlowEnabled) { return(JError(T["businessflow_disabled"])); } var data = this._dataFinder.RetrieveById(entityMeta.Name, args.RecordId); if (data.IsEmpty()) { return(NotFound()); } WorkFlow flowInfo = null; BusinessProcessFlowInstance flowInstance = null; List <ProcessStage> stages = null; Guid entityStageId = data.GetGuidValue("stageid"); int entityIndex = 0; if (args.BusinessflowId.HasValue && !args.BusinessflowId.Equals(Guid.Empty)) { flowInfo = _workFlowFinder.Find(n => n.WorkFlowId == args.BusinessflowId.Value); } else if (args.BusinessflowInstanceId.HasValue && !args.BusinessflowInstanceId.Value.Equals(Guid.Empty)) { flowInstance = _businessProcessFlowInstanceService.FindById(args.BusinessflowInstanceId.Value); if (flowInstance != null) { flowInfo = _workFlowFinder.Find(n => n.WorkFlowId == flowInstance.WorkFlowId); } } if (flowInfo == null) { var flowList = _workFlowFinder.QueryAuthorized(args.EntityId, FlowType.Business); flowInfo = flowList.NotEmpty() ? flowList.First() : null; if (flowInfo == null && !entityStageId.Equals(Guid.Empty)) { //查找当前实体所在阶段 var processstage = _processStageService.Find(n => n.ProcessStageId == entityStageId); if (processstage == null) { return(NotFound()); } flowInfo = _workFlowFinder.Find(n => n.WorkFlowId == processstage.WorkFlowId && n.StateCode == RecordState.Enabled); } } if (flowInfo == null) { return(Content("")); } stages = _processStageService.Query(n => n .Where(f => f.WorkFlowId == flowInfo.WorkFlowId) .Sort(s => s.SortAscending(f => f.StageOrder)) ); var entityIds = stages.Select(n => n.EntityId).Distinct().ToList(); entityIndex = entityIds.FindIndex(n => n.Equals(args.EntityId)) + 1; //查询业务流程实例 if (flowInstance == null) { if (entityIndex == 1) { flowInstance = _businessProcessFlowInstanceService.Find(n => n.WorkFlowId == flowInfo.WorkFlowId && n.Entity1Id == args.RecordId); } if (entityIndex == 2) { flowInstance = _businessProcessFlowInstanceService.Find(n => n.WorkFlowId == flowInfo.WorkFlowId && n.Entity2Id == args.RecordId); } if (entityIndex == 3) { flowInstance = _businessProcessFlowInstanceService.Find(n => n.WorkFlowId == flowInfo.WorkFlowId && n.Entity3Id == args.RecordId); } if (entityIndex == 4) { flowInstance = _businessProcessFlowInstanceService.Find(n => n.WorkFlowId == flowInfo.WorkFlowId && n.Entity4Id == args.RecordId); } if (entityIndex == 5) { flowInstance = _businessProcessFlowInstanceService.Find(n => n.WorkFlowId == flowInfo.WorkFlowId && n.Entity5Id == args.RecordId); } } if (flowInstance != null) { entityStageId = flowInstance.ProcessStageId.Value; } BusinessProcessModel model = new BusinessProcessModel { EntityId = args.EntityId, RecordId = args.RecordId, Data = data, BusinessFlow = flowInfo, BusinessFlowInstance = flowInstance, Stages = stages }; model.CurrentStageId = entityStageId.Equals(Guid.Empty) ? model.Stages.First().ProcessStageId : entityStageId; Dictionary <string, object> steps = new Dictionary <string, object>(); List <Schema.Domain.Attribute> attributes = new List <Schema.Domain.Attribute>(); foreach (var stage in model.Stages) { var st = new List <ProcessStep>(); st = st.DeserializeFromJson(stage.Steps); steps.Add(stage.ProcessStageId.ToString(), st); var attrs = st.Select(f => f.AttributeName).ToList(); attributes.AddRange(_attributeFinder.Query(n => n.Where(f => f.Name.In(attrs) && f.EntityId == stage.EntityId))); } model.Steps = steps; model.Attributes = attributes; var related = model.Stages.Where(n => n.RelationshipName.IsNotEmpty()).ToList(); if (related.NotEmpty()) { var rnames = related.Select(f => f.RelationshipName).ToList(); model.RelationShips = _relationShipFinder.Query(n => n.Where(f => f.Name.In(rnames))); _relationShipFinder.WrapLocalizedLabel(model.RelationShips); } if (model.BusinessFlowInstance != null) { var rsRecords = new Dictionary <string, object>(); int i = 1; foreach (var eid in entityIds) { var eidMeta = _entityFinder.FindById(eid); var filter = new Dictionary <string, object>(); if (i == 1 && flowInstance.Entity1Id.HasValue && !flowInstance.Entity1Id.Value.Equals(Guid.Empty)) { filter.Add(eidMeta.Name + "id", flowInstance.Entity1Id); } if (i == 2 && flowInstance.Entity2Id.HasValue && !flowInstance.Entity2Id.Value.Equals(Guid.Empty)) { filter.Add(eidMeta.Name + "id", flowInstance.Entity2Id); } if (i == 3 && flowInstance.Entity3Id.HasValue && !flowInstance.Entity3Id.Value.Equals(Guid.Empty)) { filter.Add(eidMeta.Name + "id", flowInstance.Entity3Id); } if (i == 4 && flowInstance.Entity4Id.HasValue && !flowInstance.Entity4Id.Value.Equals(Guid.Empty)) { filter.Add(eidMeta.Name + "id", flowInstance.Entity4Id); } if (i == 5 && flowInstance.Entity5Id.HasValue && !flowInstance.Entity5Id.Value.Equals(Guid.Empty)) { filter.Add(eidMeta.Name + "id", flowInstance.Entity5Id); } if (filter.Count > 0) { rsRecords.Add(eid.ToString(), _dataFinder.RetrieveByAttribute(eidMeta.Name, filter)); } else { rsRecords.Add(eid.ToString(), null); } i++; } model.RelatedRecords = rsRecords; } return(View($"~/Views/Flow/{WebContext.ActionName}.cshtml", model)); }
public IActionResult Get(Guid id) { var result = _entityFinder.FindById(id); return(JOk(result)); }
public static object WrapAttributeValue(this Entity entity, IEntityFinder entityFinder, Schema.Domain.Attribute attr, object value) { List <string> errors = new List <string>(); if (value == null || value.ToString().IsEmpty()) { return(null); } if (attr != null) { if (attr.TypeIsBit()) { if (value.ToString().IsInteger())// if value is 0/1 { value = value.ToString() == "1"; } else { var boolValue = true; if (bool.TryParse(value.ToString(), out boolValue)) { value = boolValue; } else//if (!(value is bool)) { errors.Add(string.Format("{0}'s value({1}) is not valid, it's type should be 'bool'", attr.Name, value.ToString())); } } } else if (attr.TypeIsLookUp()) { if (value is EntityReference) { var er = value as EntityReference; //是否存在该引用实体 if (!entityFinder.Exists(er.ReferencedEntityName)) { errors.Add(string.Format("referenced entity '{0}' is not found by attribute '{1}'", er.ReferencedEntityName, attr.Name)); } } else { if (value.ToString().IsGuid()) { var referencedEntity = entityFinder.FindById(attr.ReferencedEntityId.Value); value = new EntityReference(referencedEntity.Name, Guid.Parse(value.ToString())); } else { errors.Add(string.Format("{0}'s value({1}) is not valid, it's type should be 'SDK.EntityReference'", attr.Name, value.ToString())); } } } else if (attr.TypeIsPickList()) { //是否正确的格式 if (!(value is OptionSetValue)) { if (value.ToString().IsInteger()) { value = new OptionSetValue(int.Parse(value.ToString())); } else { errors.Add(string.Format("{0}'s value({1}) is not valid, it's type should be 'SDK.OptionSetValue'", attr.Name, value.ToString())); } } //是否存在该值 } else if (attr.TypeIsOwner()) { //是否正确的格式 if (!(value is OwnerObject)) { if (value.ToString().IsGuid()) { value = new OwnerObject(OwnerTypes.SystemUser, Guid.Parse(value.ToString())); } else { errors.Add(string.Format("{0}'s value({1}) is not valid, it's type should be 'SDK.OwnerObject'", attr.Name, value.ToString())); } } //是否存在该值 } else if (attr.TypeIsState()) { if (value.ToString().IsInteger())// if value is 0/1 { value = value.ToString() == "1"; } else { var boolValue = true; if (bool.TryParse(value.ToString(), out boolValue)) { value = boolValue; } else//if (!(value is bool)) { errors.Add(string.Format("{0}'s value({1}) is not valid, it's type should be 'bool'", attr.Name, value.ToString())); } } } else if (attr.TypeIsInt()) { //是否正确的格式 if (!value.ToString().IsInteger()) { errors.Add(string.Format("{0}'s value({1}) is not valid, it's type should be 'int'", attr.Name, value.ToString())); } } else if (attr.TypeIsFloat()) { //是否正确的格式 if (!value.ToString().IsNumeric()) { errors.Add(string.Format("{0}'s value({1}) is not valid, it's type should be 'float'", attr.Name, value.ToString())); } } else if (attr.TypeIsMoney()) { //是否正确的格式 if (!(value is Money)) { if (value.ToString().IsNumeric()) { value = new Money(decimal.Parse(value.ToString())); } else { errors.Add(string.Format("{0}'s value({1}) is not valid, it's type should be 'SDK.Money'", attr.Name, value.ToString())); } } } else if (attr.TypeIsDateTime()) { //是否正确的格式 if (!value.ToString().IsDateTime()) { errors.Add(string.Format("{0}'s value({1}) is not valid, it's type should be 'datetime'", attr.Name, value.ToString())); } } } if (errors.NotEmpty()) { throw new XmsException(string.Join("\n", errors)); } return(value); }
public IActionResult Post(DataUpdateModel model) { Schema.Domain.Entity entityMeta = null; if (model.EntityId.HasValue && !model.EntityId.Value.Equals(Guid.Empty)) { entityMeta = _entityFinder.FindById(model.EntityId.Value); } else if (model.EntityName.IsNotEmpty()) { entityMeta = _entityFinder.FindByName(model.EntityName); } if (entityMeta == null) { return(NotFound()); } var childAttributes = _attributeFinder.FindByEntityName(entityMeta.Name); var primaryAttr = childAttributes.Find(n => n.TypeIsPrimaryKey()); if (model.Data.StartsWith("[")) { //var details = new List<Entity>(); var items = JArray.Parse(model.Data.UrlDecode()); if (items.Count > 0) { foreach (var c in items) { dynamic root = JObject.Parse(c.ToString()); Entity detail = new Entity(entityMeta.Name); foreach (JProperty p in root) { if (p.Name.IsCaseInsensitiveEqual("id")) { detail.SetIdValue(Guid.Parse(p.Value.ToString()), primaryAttr.Name); } else { var attr = childAttributes.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name)); if (attr != null) { detail.SetAttributeValue(p.Name.ToString().ToLower(), detail.WrapAttributeValue(_entityFinder, attr, p.Value.ToString())); } } } //details.Add(detail); _dataUpdater.Update(detail); } } //_organizationServiceProxy.UpdateMany(details); return(UpdateSuccess()); } else { Entity detail = new Entity(entityMeta.Name); dynamic root = JObject.Parse(model.Data.UrlDecode()); foreach (JProperty p in root) { if (p.Name.IsCaseInsensitiveEqual("id")) { detail.SetIdValue(Guid.Parse(p.Value.ToString()), primaryAttr.Name); } else { var attr = childAttributes.Find(n => n.Name.IsCaseInsensitiveEqual(p.Name)); if (attr != null) { detail.SetAttributeValue(p.Name.ToString().ToLower(), detail.WrapAttributeValue(_entityFinder, attr, p.Value.ToString())); } } } _dataUpdater.Update(detail); } return(UpdateSuccess()); }
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); }
public IActionResult KanbanView([FromBody, FromQuery] KanbanGridModel model) { if (model.AggregateField.IsEmpty() || model.GroupField.IsEmpty()) { return(JError("请指定统计字段及分组字段")); } QueryView.Domain.QueryView queryView = null; if (model.QueryId.HasValue && !model.QueryId.Equals(Guid.Empty)) { queryView = _queryViewFinder.FindById(model.QueryId.Value); } if (queryView == null) { return(NotFound()); } if (!queryView.IsDefault && queryView.AuthorizationEnabled) { if (!_roleObjectAccessService.Exists(queryView.QueryViewId, QueryViewDefaults.ModuleName, CurrentUser.Roles.Select(n => n.RoleId).ToArray())) { return(Unauthorized()); } } model.QueryView = queryView; model.EntityId = queryView.EntityId; model.QueryId = queryView.QueryViewId; model.EntityName = _entityFinder.FindById(model.EntityId.Value).Name; var attributes = new List <Schema.Domain.Attribute>(); var aggAttr = _attributeFinder.Find(model.EntityId.Value, model.AggregateField); attributes.Add(aggAttr); var queryExp = new QueryExpression(); queryExp = queryExp.DeserializeFromJson(queryView.FetchConfig); var orderExp = new OrderExpression("createdon", OrderType.Descending); queryExp.Orders.Add(orderExp); Dictionary <string, AggregateType> attributeAggs = new Dictionary <string, AggregateType>(); if (aggAttr.TypeIsInt() || aggAttr.TypeIsFloat() || aggAttr.TypeIsDecimal() || aggAttr.TypeIsMoney()) { attributeAggs.Add(model.AggregateField, AggregateType.Sum); model.AggType = AggregateType.Sum; } else { attributeAggs.Add(model.AggregateField, AggregateType.Count); model.AggType = AggregateType.Count; } var datas = _aggregateService.Execute(queryExp, attributeAggs, new List <string>() { model.GroupField }); model.Items = datas; queryExp.ColumnSet.Columns.Clear(); queryExp.ColumnSet.AddColumns("createdon", model.AggregateField, model.GroupField, "ownerid"); model.GroupingDatas = _aggregateService.GroupingTop(model.GroupingTop, model.GroupField, queryExp, orderExp); var groupAttr = _attributeFinder.Find(model.EntityId.Value, model.GroupField); groupAttr.OptionSet = _optionSetFinder.FindById(groupAttr.OptionSetId.Value); attributes.Add(groupAttr); model.AttributeList = attributes; return(View($"~/Views/Entity/{WebContext.ActionName}.cshtml", model)); }
public IActionResult Post(CreateAttributeModel model) { if (ModelState.IsValid) { var entity = _entityFinder.FindById(model.EntityId); if (entity == null) { return(NotFound()); } var attr = _attributeFinder.Find(model.EntityId, model.Name); if (attr != null) { return(JError(T["attribute_name_exists"])); } var attrInfo = new Schema.Domain.Attribute(); //model.CopyTo(entity); attrInfo.EntityId = entity.EntityId; attrInfo.EntityName = entity.Name; attrInfo.Name = model.Name.Trim(); attrInfo.LocalizedName = model.LocalizedName; attrInfo.AttributeId = Guid.NewGuid(); attrInfo.IsNullable = model.IsNullable; attrInfo.IsRequired = model.IsRequired; attrInfo.LogEnabled = model.IsLoged; attrInfo.IsCustomizable = true; attrInfo.IsCustomField = true; attrInfo.AuthorizationEnabled = model.IsSecured; attrInfo.CreatedBy = CurrentUser.SystemUserId; attrInfo.Description = model.Description; attrInfo.ValueType = model.ValueType; switch (model.AttributeType) { case AttributeTypeIds.NVARCHAR: attrInfo.MaxLength = model.MaxLength.Value; attrInfo.DataFormat = model.TextFormat; attrInfo.DefaultValue = model.DefaultValue; if (model.ValueType == 2) { attrInfo.FormulaExpression = model.FormulaExpression; } break; case AttributeTypeIds.NTEXT: attrInfo.DataFormat = model.NTextFormat; break; case AttributeTypeIds.INT: attrInfo.MinValue = model.IntMinValue.Value <= int.MinValue ? int.MinValue + 2 : model.IntMinValue.Value; attrInfo.MaxValue = model.IntMaxValue.Value >= int.MaxValue ? int.MaxValue - 2 : model.IntMaxValue.Value; attrInfo.DefaultValue = model.DefaultValue; if (model.ValueType == 2) { attrInfo.FormulaExpression = model.FormulaExpression; } else if (model.ValueType == 3) { attrInfo.SummaryEntityId = model.SummaryEntityId; attrInfo.SummaryExpression = model.SummaryExpression; } break; case AttributeTypeIds.FLOAT: attrInfo.Precision = model.FloatPrecision.Value; attrInfo.MinValue = model.FloatMinValue.Value <= float.MinValue ? float.MinValue + 2 : model.FloatMinValue.Value; attrInfo.MaxValue = model.FloatMaxValue.Value >= float.MaxValue ? float.MaxValue - 2 : model.FloatMaxValue.Value; attrInfo.DefaultValue = model.DefaultValue; if (model.ValueType == 2) { attrInfo.FormulaExpression = model.FormulaExpression; } else if (model.ValueType == 3) { attrInfo.SummaryEntityId = model.SummaryEntityId; attrInfo.SummaryExpression = model.SummaryExpression; } break; case AttributeTypeIds.MONEY: attrInfo.Precision = model.MoneyPrecision.Value; attrInfo.MinValue = model.MoneyMinValue.Value <= float.MinValue ? float.MinValue + 2 : model.MoneyMinValue.Value; attrInfo.MaxValue = model.MoneyMaxValue.Value >= float.MaxValue ? float.MaxValue - 2 : model.MoneyMaxValue.Value; attrInfo.DefaultValue = model.DefaultValue; if (model.ValueType == 2) { attrInfo.FormulaExpression = model.FormulaExpression; } else if (model.ValueType == 3) { attrInfo.SummaryEntityId = model.SummaryEntityId; attrInfo.SummaryExpression = model.SummaryExpression; } break; case AttributeTypeIds.PICKLIST: attrInfo.DisplayStyle = model.OptionSetType; if (model.IsCommonOptionSet) { attrInfo.OptionSetId = model.CommonOptionSet.Value; } else { if (model.OptionSetName.IsEmpty()) { return(JError(T["attribute_options_empty"])); } //新建选项集 Schema.Domain.OptionSet os = new Schema.Domain.OptionSet(); os.OptionSetId = Guid.NewGuid(); os.Name = model.Name; os.IsPublic = false; List <Schema.Domain.OptionSetDetail> details = new List <Schema.Domain.OptionSetDetail>(); int i = 0; foreach (var item in model.OptionSetName) { if (item.IsEmpty()) { continue; } Schema.Domain.OptionSetDetail osd = new Schema.Domain.OptionSetDetail(); osd.OptionSetDetailId = Guid.NewGuid(); osd.OptionSetId = os.OptionSetId; osd.Name = item; osd.Value = model.OptionSetValue[i]; osd.IsSelected = model.IsSelectedOption[i]; osd.DisplayOrder = i; details.Add(osd); i++; } attrInfo.OptionSetId = os.OptionSetId; os.Items = details; attrInfo.OptionSet = os; } break; case AttributeTypeIds.BIT: if (model.BitOptionName.IsEmpty()) { return(JError(T["attribute_options_empty"])); } //新建选项集 List <Schema.Domain.StringMap> pickListItems = new List <Schema.Domain.StringMap>(); int j = 0; foreach (var item in model.BitOptionName) { Schema.Domain.StringMap s = new Schema.Domain.StringMap(); s.StringMapId = Guid.NewGuid(); s.Name = item; s.Value = j == 0 ? 1 : 0;//第一项为true选项 s.DisplayOrder = j; s.AttributeId = attrInfo.AttributeId; s.EntityName = attrInfo.EntityName; s.AttributeName = attrInfo.Name; j++; pickListItems.Add(s); } attrInfo.PickLists = pickListItems; break; case AttributeTypeIds.DATETIME: attrInfo.DataFormat = model.DateTimeFormat; break; case AttributeTypeIds.LOOKUP: attrInfo.ReferencedEntityId = model.LookupEntity.Value; break; case AttributeTypeIds.PARTYLIST: attrInfo.DataFormat = model.PartyListFormat; break; } attrInfo.AttributeTypeName = model.AttributeType; _attributeCreater.Create(attrInfo); return(CreateSuccess(new { id = attrInfo.AttributeId })); } return(JModelError(T["created_error"])); }