public bool Create(Domain.SerialNumberRule entity)
        {
            //检查是否已存在相同字段的编码规则
            if (_serialNumberRuleRepository.Exists(x => x.EntityId == entity.EntityId && x.AttributeId == entity.AttributeId))
            {
                throw new XmsException(_loc["serial_number_duplicated"]);
            }
            entity.OrganizationId = this._appContext.OrganizationId;
            var result = true;

            using (UnitOfWork.Build(_serialNumberRuleRepository.DbContext))
            {
                result = _serialNumberRuleRepository.Create(entity);
                //依赖于字段
                _dependencyService.Create(entity);
                //solution component
                result = _solutionComponentService.Create(entity.SolutionId, entity.SerialNumberRuleId, SerialNumberRuleDefaults.ModuleName);
                //本地化标签
                _localizedLabelService.Create(entity.SolutionId, entity.Name.IfEmpty(""), SerialNumberRuleDefaults.ModuleName, "LocalizedName", entity.SerialNumberRuleId, this._appContext.BaseLanguage);
                _localizedLabelService.Create(entity.SolutionId, entity.Description.IfEmpty(""), SerialNumberRuleDefaults.ModuleName, "Description", entity.SerialNumberRuleId, this._appContext.BaseLanguage);
                //plugin
                _entityPluginCreater.Create(new EntityPlugin()
                {
                    AssemblyName = SerialNumberRuleDefaults.AssemblyName
                    ,
                    ClassName = SerialNumberRuleDefaults.PluginClassName
                    ,
                    EntityId = entity.EntityId
                    ,
                    EventName = Enum.GetName(typeof(OperationTypeEnum), OperationTypeEnum.Create)
                    ,
                    IsVisibled = false
                    ,
                    TypeCode = 0
                    ,
                    StateCode = RecordState.Enabled
                });
                //add to cache
                _cacheService.SetEntity(_serialNumberRuleRepository.FindById(entity.SerialNumberRuleId));
            }
            return(result);
        }
Exemple #2
0
        public bool Import(string file, Guid solutionId, LanguageCode baseLanguageId)
        {
            var data      = new DataTable();// _dataImporter.ExcelToDataTable(file);
            var languages = _languageService.Query(n => n.Sort(s => s.SortAscending(f => f.Name)));

            foreach (DataRow row in data.Rows)
            {
                var objectId = Guid.Parse(row[0].ToString());
                var name     = row[1].ToString();
                var typeCode = int.Parse(row[2].ToString());
                foreach (var lg in languages)
                {
                    if (data.Columns.Contains(lg.UniqueId.ToString()))
                    {
                        var label         = row[lg.UniqueId.ToString()] != null ? row[lg.UniqueId.ToString()].ToString() : string.Empty;
                        var originalLabel = _localizedLabelService.Find(n => n.ObjectId == objectId && n.ObjectColumnName == name && (int)n.LanguageId == lg.UniqueId);
                        if (originalLabel != null)
                        {
                            if (label.IsEmpty())
                            {
                                _localizedLabelService.DeleteById(originalLabel.LocalizedLabelId);
                            }
                            else if (!label.IsCaseInsensitiveEqual(originalLabel.Label))
                            {
                                originalLabel.Label = label;
                                _localizedLabelService.Update(originalLabel);
                            }
                        }
                        else if (label.IsNotEmpty())
                        {
                            _localizedLabelService.Create(solutionId, label, typeCode.ToString(), name, objectId, (LanguageCode)Enum.Parse(typeof(LanguageCode), lg.UniqueId.ToString()));
                        }
                    }
                }
            }
            return(true);
        }