Beispiel #1
0
        public static string GetNameField(this Domain.Attribute attr, string alias = "")
        {
            if (attr == null)
            {
                return(string.Empty);
            }

            var field = alias.IsNotEmpty() ? alias : attr.Name;

            if (attr.TypeIsLookUp() || attr.TypeIsOwner() || attr.TypeIsCustomer() || attr.TypeIsState() || attr.TypeIsBit() || attr.TypeIsPickList() || attr.TypeIsStatus())
            {
                field += "name";
            }
            return(field);
        }
Beispiel #2
0
 public bool Update(Domain.Attribute entity)
 {
     //引用类型
     if (entity.TypeIsLookUp() || entity.TypeIsOwner() || entity.TypeIsCustomer())
     {
         var referenced = _attributeRepository.Find(x => x.EntityId == entity.ReferencedEntityId.Value && x.AttributeTypeName == AttributeTypeIds.PRIMARYKEY);
         _dependencyService.Update(AttributeDefaults.ModuleName, entity.AttributeId, EntityDefaults.ModuleName, entity.ReferencedEntityId.Value);
         _dependencyService.Update(AttributeDefaults.ModuleName, entity.AttributeId, AttributeDefaults.ModuleName, referenced.AttributeId);
     }
     //选项类型
     else if (entity.TypeIsPickList())
     {
         if (entity.OptionSet != null && entity.OptionSet.IsPublic)
         {
             //依赖于公共选项集
             _dependencyService.Update(AttributeDefaults.ModuleName, entity.AttributeId, OptionSetDefaults.ModuleName, entity.OptionSetId.Value);
         }
     }
     return(true);
 }
Beispiel #3
0
        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);
        }