コード例 #1
0
ファイル: RelationShipFinder.cs プロジェクト: zzdxpq007/xms
        public void WrapLocalizedLabel(Domain.RelationShip entity)
        {
            var rcingEntity = _entityFinder.FindById(entity.ReferencingEntityId);

            if (rcingEntity != null)
            {
                entity.ReferencingEntityLocalizedName = rcingEntity.LocalizedName;
            }
            var rcingAttr = _attributeFinder.FindById(entity.ReferencingAttributeId);

            if (rcingAttr != null)
            {
                entity.ReferencingAttributeLocalizedName = rcingAttr.LocalizedName;
            }
            var rcedEntity = _entityFinder.FindById(entity.ReferencedEntityId);

            if (rcedEntity != null)
            {
                entity.ReferencedEntityLocalizedName = rcedEntity.LocalizedName;
            }
            var rcedAttr = _attributeFinder.FindById(entity.ReferencedAttributeId);

            if (rcedAttr != null)
            {
                entity.ReferencedAttributeLocalizedName = rcedAttr.LocalizedName;
            }
        }
コード例 #2
0
ファイル: RelationShipFinder.cs プロジェクト: zzdxpq007/xms
        public Domain.RelationShip FindByName(string name)
        {
            var dic = new Dictionary <string, string>();

            dic.Add("name", name);

            Domain.RelationShip entity = _cacheService.Get(dic, () =>
            {
                return(_relationShipRepository.Find(x => x.Name == name));
            });
            return(entity);
        }
コード例 #3
0
ファイル: RelationShipFinder.cs プロジェクト: zzdxpq007/xms
        public Domain.RelationShip FindById(Guid id)
        {
            var dic = new Dictionary <string, string>();

            dic.Add("RelationshipId", id.ToString());

            Domain.RelationShip entity = _cacheService.Get(dic, () =>
            {
                return(_relationShipRepository.FindById(id));
            });
            return(entity);
        }
コード例 #4
0
ファイル: RelationShipUpdater.cs プロジェクト: zzdxpq007/xms
        public bool Update(Domain.RelationShip entity)
        {
            bool flag = _relationShipRepository.Update(entity);

            if (flag)
            {
                //this.WrapLocalizedLabel(entity);
                //set to cache
                _cacheService.SetEntity(entity);
            }
            return(flag);
        }
コード例 #5
0
ファイル: RelationShipCreater.cs プロジェクト: zzdxpq007/xms
        public bool Create(Domain.RelationShip entity)
        {
            entity.SolutionId = SolutionDefaults.DefaultSolutionId;//组件属于默认解决方案
            bool result = _relationShipRepository.Create(entity);

            if (result)
            {
                //this.WrapLocalizedLabel(entity);
                //这里缓存对象会不完整
            }
            return(result);
        }
コード例 #6
0
        public List <Domain.RelationShip> GetSysAttributeRelationShips(Domain.Entity entity, List <Domain.Attribute> sysAttributes)
        {
            var primaryFields          = _attributeFinder.Query(x => x.Where(f => f.EntityName.In("SystemUser", "BusinessUnit", "Organization", "WorkFlow") && f.Name.In("SystemUserId", "BusinessUnitId", "OrganizationId", "WorkFlowId")));
            var systemUserPrimaryKey   = primaryFields.Find(x => x.Name == "SystemUserId");
            var businessUnitPrimaryKey = primaryFields.Find(x => x.Name == "BusinessUnitId");
            var organizationPrimaryKey = primaryFields.Find(x => x.Name == "OrganizationId");
            var workFlowPrimaryKey     = primaryFields.Find(x => x.Name == "WorkFlowId");
            List <Domain.RelationShip> relationships = new List <Domain.RelationShip>();

            if (sysAttributes.Exists(n => n.Name.IsCaseInsensitiveEqual("CreatedBy")))
            {
                var createdByRelationShip = new Domain.RelationShip
                {
                    Name                     = "lk_" + entity.Name + "_createdby",
                    RelationshipType         = RelationShipType.ManyToOne,
                    ReferencingAttributeId   = sysAttributes.Find(n => n.Name.IsCaseInsensitiveEqual("CreatedBy")).AttributeId,
                    ReferencingAttributeName = "CreatedBy",
                    ReferencedEntityName     = "SystemUser",
                    ReferencedAttributeName  = "SystemUserId",
                    ReferencingEntityId      = entity.EntityId,
                    ReferencedAttributeId    = systemUserPrimaryKey.AttributeId,
                    ReferencedEntityId       = systemUserPrimaryKey.EntityId
                };
                relationships.Add(createdByRelationShip);
            }
            if (sysAttributes.Exists(n => n.Name.IsCaseInsensitiveEqual("ModifiedBy")))
            {
                var modifiedByRelationShip = new Domain.RelationShip
                {
                    Name                     = "lk_" + entity.Name + "_modifiedby",
                    RelationshipType         = RelationShipType.ManyToOne,
                    ReferencingAttributeId   = sysAttributes.Find(n => n.Name == "ModifiedBy").AttributeId,
                    ReferencingAttributeName = "ModifiedBy",
                    ReferencedEntityName     = "SystemUser",
                    ReferencedAttributeName  = "SystemUserId",
                    ReferencingEntityId      = entity.EntityId,
                    ReferencedAttributeId    = systemUserPrimaryKey.AttributeId,
                    ReferencedEntityId       = systemUserPrimaryKey.EntityId
                };
                relationships.Add(modifiedByRelationShip);
            }
            if (entity.EntityMask == EntityMaskEnum.User)
            {
                if (sysAttributes.Exists(n => n.Name.IsCaseInsensitiveEqual("OwnerId")))
                {
                    var ownerIdRelationShip = new Domain.RelationShip
                    {
                        Name                     = "lk_" + entity.Name + "_ownerid",
                        RelationshipType         = RelationShipType.ManyToOne,
                        ReferencingAttributeId   = sysAttributes.Find(n => n.Name.IsCaseInsensitiveEqual("OwnerId")).AttributeId,
                        ReferencingAttributeName = "OwnerId",
                        ReferencedEntityName     = "SystemUser",
                        ReferencedAttributeName  = "SystemUserId",
                        ReferencingEntityId      = entity.EntityId,
                        ReferencedAttributeId    = systemUserPrimaryKey.AttributeId,
                        ReferencedEntityId       = systemUserPrimaryKey.EntityId
                    };
                    relationships.Add(ownerIdRelationShip);
                }
                if (sysAttributes.Exists(n => n.Name.IsCaseInsensitiveEqual("OwningBusinessUnit")))
                {
                    var owningBusinessUnitRelationShip = new Domain.RelationShip
                    {
                        Name                     = "lk_" + entity.Name + "_owningbusinessunit",
                        RelationshipType         = RelationShipType.ManyToOne,
                        ReferencingAttributeId   = sysAttributes.Find(n => n.Name.IsCaseInsensitiveEqual("OwningBusinessUnit")).AttributeId,
                        ReferencingAttributeName = "OwningBusinessUnit",
                        ReferencedEntityName     = "BusinessUnit",
                        ReferencedAttributeName  = "BusinessUnitId",
                        ReferencingEntityId      = entity.EntityId,
                        ReferencedAttributeId    = businessUnitPrimaryKey.AttributeId,
                        ReferencedEntityId       = businessUnitPrimaryKey.EntityId
                    };
                    relationships.Add(owningBusinessUnitRelationShip);
                }
            }
            if (sysAttributes.Exists(n => n.Name.IsCaseInsensitiveEqual("OrganizationId")))
            {
                var organizationIdRelationShip = new Domain.RelationShip
                {
                    Name                     = "lk_" + entity.Name + "_organizationid",
                    RelationshipType         = RelationShipType.ManyToOne,
                    ReferencingAttributeId   = sysAttributes.Find(n => n.Name.IsCaseInsensitiveEqual("OrganizationId")).AttributeId,
                    ReferencingAttributeName = "OrganizationId",
                    ReferencedEntityName     = "Organization",
                    ReferencedAttributeName  = "OrganizationId",
                    ReferencingEntityId      = entity.EntityId,
                    ReferencedAttributeId    = organizationPrimaryKey.AttributeId,
                    ReferencedEntityId       = organizationPrimaryKey.EntityId
                };
                relationships.Add(organizationIdRelationShip);
            }
            if (entity.WorkFlowEnabled)
            {
                if (sysAttributes.Exists(n => n.Name.IsCaseInsensitiveEqual("WorkFlowId")))
                {
                    var workflowIdRelationShip = new Domain.RelationShip
                    {
                        Name                     = "lk_" + entity.Name + "_workflowid",
                        RelationshipType         = RelationShipType.ManyToOne,
                        ReferencingAttributeId   = sysAttributes.Find(n => n.Name.IsCaseInsensitiveEqual("WorkFlowId")).AttributeId,
                        ReferencingAttributeName = "WorkFlowId",
                        ReferencedEntityName     = "WorkFlow",
                        ReferencedAttributeName  = "WorkFlowId",
                        ReferencingEntityId      = entity.EntityId,
                        ReferencedAttributeId    = workFlowPrimaryKey.AttributeId,
                        ReferencedEntityId       = workFlowPrimaryKey.EntityId
                    };
                    relationships.Add(workflowIdRelationShip);
                }
            }
            return(relationships);
        }
コード例 #7
0
ファイル: AttributeCreater.cs プロジェクト: xixiky/xms
        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);
        }
コード例 #8
0
ファイル: RelationShipCache.cs プロジェクト: zzdxpq007/xms
 public static string BuildKey(Domain.RelationShip entity)
 {
     return(entity.ReferencingEntityId + "/" + entity.ReferencedEntityId + "/" + entity.RelationshipId + "/" + entity.Name + "/");
 }