public bool Import(Guid solutionId, IList <EntityMapXmlInfo> entityMaps) { if (entityMaps.NotEmpty()) { foreach (var item in entityMaps) { var entity = _entityMapFinder.FindById(item.EntityMapId); if (entity != null) { _entityMapUpdater.Update(item); if (item.AttributeMaps.NotEmpty()) { _attributeMapDeleter.DeleteByParentId(entity.EntityMapId); _attributeMapCreater.CreateMany(item.AttributeMaps); } } else { item.CreatedBy = _appContext.GetFeature <ICurrentUser>().SystemUserId; item.SolutionId = solutionId; item.ComponentState = 0; item.CreatedOn = DateTime.Now; _entityMapCreater.Create(item); } } } return(true); }
public IActionResult CreateEntityMap(EditEntityMapModel model) { if (ModelState.IsValid) { //已存在的单据头映射 var headEntityMap = _entityMapFinder.Find(model.SourceEntityId, model.EntityId); if (headEntityMap != null) { return(JError(T["entitymap_duplicated"])); } //已存在的单据体映射 if (model.ChildAttributeMap.NotEmpty() && !model.ChildSourceEntityId.Equals(Guid.Empty) && !model.ChildTargetEntityId.Equals(Guid.Empty)) { var childEntityMap = _entityMapFinder.Find(model.ChildSourceEntityId, model.ChildTargetEntityId); if (childEntityMap != null) { return(JError(T["entitymap_duplicated"])); } } var id = Guid.NewGuid(); //单据头 if (model.HeadAttributeMap.NotEmpty()) { var entMapTable = new EntityMap { ComponentState = 0, SolutionId = SolutionId.Value, OrganizationId = CurrentUser.OrganizationId, CreatedBy = CurrentUser.SystemUserId, CreatedOn = DateTime.Now, EntityMapId = id, SourceEntityId = model.SourceEntityId, TargetEntityId = model.EntityId, RelationShipName = model.RelationShipName, MapType = model.MapType, StateCode = RecordState.Enabled }; var headAttributeMap = new List <AttributeMap>(); foreach (var item in model.HeadAttributeMap) { if (!item.SourceAttributeId.Equals(Guid.Empty)) { var attributeMap = new AttributeMap { AttributeMapId = Guid.NewGuid(), CanChange = item.CanChange, EntityMapId = entMapTable.EntityMapId, TargetAttributeId = item.TargetAttributeId, SourceAttributeId = item.SourceAttributeId }; if (model.HeadControlAttributeMap.NotEmpty()) { var controlAttrMap = model.HeadControlAttributeMap.Find(n => n.SourceAttributeId == item.SourceAttributeId); if (controlAttrMap != null) { attributeMap.RemainAttributeId = controlAttrMap.RemainAttributeId; attributeMap.ClosedAttributeId = controlAttrMap.ClosedAttributeId; } } headAttributeMap.Add(attributeMap); } } if (headAttributeMap.IsEmpty()) { return(JError(T["entitymap_emptyheadattributemap"])); } _entityMapCreater.Create(entMapTable); _attributeMapCreater.CreateMany(headAttributeMap); //单据体 if (model.ChildAttributeMap.NotEmpty() && !model.ChildSourceEntityId.Equals(Guid.Empty) && !model.ChildTargetEntityId.Equals(Guid.Empty)) { var childEntityMap = new EntityMap { ComponentState = 0, SolutionId = SolutionId.Value, OrganizationId = CurrentUser.OrganizationId, CreatedBy = CurrentUser.SystemUserId, CreatedOn = DateTime.Now, EntityMapId = Guid.NewGuid(), SourceEntityId = model.ChildSourceEntityId, TargetEntityId = model.ChildTargetEntityId, RelationShipName = model.ChildRelationShipName, ParentEntityMapId = entMapTable.EntityMapId, MapType = model.MapType, StateCode = RecordState.Enabled }; var childAttributeMap = new List <AttributeMap>(); foreach (var item in model.ChildAttributeMap) { if (!item.SourceAttributeId.Equals(Guid.Empty)) { var attributeMap = new AttributeMap { AttributeMapId = Guid.NewGuid(), CanChange = item.CanChange, EntityMapId = childEntityMap.EntityMapId, TargetAttributeId = item.TargetAttributeId, SourceAttributeId = item.SourceAttributeId }; if (model.ChildControlAttributeMap.NotEmpty()) { var controlAttrMap = model.ChildControlAttributeMap.Find(n => n.SourceAttributeId == item.SourceAttributeId); if (controlAttrMap != null) { attributeMap.RemainAttributeId = controlAttrMap.RemainAttributeId; attributeMap.ClosedAttributeId = controlAttrMap.ClosedAttributeId; } } childAttributeMap.Add(attributeMap); } } if (childAttributeMap.IsEmpty()) { return(JError(T["entitymap_emptychildattributemap"])); } _entityMapCreater.Create(childEntityMap); _attributeMapCreater.CreateMany(childAttributeMap); } } return(CreateSuccess(new { id = id })); } return(CreateFailure(GetModelErrors())); }