Exemplo n.º 1
0
 public bool Import(Guid solutionId, IList <DuplicateRule> duplicateRules)
 {
     if (duplicateRules.NotEmpty())
     {
         foreach (var item in duplicateRules)
         {
             var entity = _duplicateRuleFinder.FindById(item.DuplicateRuleId);
             if (entity != null)
             {
                 _duplicateRuleUpdater.Update(item);
                 if (item.Conditions.NotEmpty())
                 {
                     _duplicateRuleConditionService.DeleteByParentId(entity.DuplicateRuleId);
                     foreach (var cnd in item.Conditions)
                     {
                         cnd.DuplicateRuleId = item.DuplicateRuleId;
                     }
                     _duplicateRuleConditionService.CreateMany(item.Conditions);
                 }
             }
             else
             {
                 item.CreatedBy      = _appContext.GetFeature <ICurrentUser>().SystemUserId;
                 item.SolutionId     = solutionId;
                 item.ComponentState = 0;
                 item.CreatedOn      = DateTime.Now;
                 _duplicateRuleCreater.Create(item);
             }
         }
     }
     return(true);
 }
Exemplo n.º 2
0
        public bool Create(DuplicateRule entity)
        {
            entity.SolutionId = SolutionDefaults.DefaultSolutionId;//组件属于默认解决方案
            var result = false;

            using (UnitOfWork.Build(_duplicateRuleRepository.DbContext))
            {
                result = _duplicateRuleRepository.Create(entity);
                //检测条件
                if (entity.Conditions.NotEmpty())
                {
                    foreach (var item in entity.Conditions)
                    {
                        item.EntityId = entity.EntityId;
                    }
                    result = _duplicateRuleConditionService.CreateMany(entity.Conditions);
                }
                //依赖于字段
                _dependencyService.Create(entity);
                //本地化标签
                _localizedLabelService.Create(entity.SolutionId, entity.Name.IfEmpty(""), DuplicateRuleDefaults.ModuleName, "LocalizedName", entity.DuplicateRuleId, this._appContext.BaseLanguage);
                _localizedLabelService.Create(entity.SolutionId, entity.Description.IfEmpty(""), DuplicateRuleDefaults.ModuleName, "Description", entity.DuplicateRuleId, this._appContext.BaseLanguage);
                //plugin
                _entityPluginCreater.Create(new EntityPlugin()
                {
                    AssemblyName = DuplicateRuleDefaults.AssemblyName
                    ,
                    ClassName = DuplicateRuleDefaults.PluginClassName
                    ,
                    EntityId = entity.EntityId
                    ,
                    EventName = Enum.GetName(typeof(OperationTypeEnum), OperationTypeEnum.Create)
                    ,
                    IsVisibled = false
                    ,
                    TypeCode = 0
                    ,
                    StateCode = RecordState.Enabled
                });
                //add to cache
                _cacheService.SetEntity(entity);
            }
            return(result);
        }