コード例 #1
0
        public void Save(List <ModuleOptionStorageModel> descriptors)
        {
            if (descriptors == null || !descriptors.Any())
            {
                return;
            }

            using var uow = _dbContext.NewUnitOfWork();
            foreach (var descriptor in descriptors)
            {
                var newEntity = new ConfigEntity
                {
                    Type    = ConfigType.Module,
                    Key     = descriptor.Key,
                    Value   = descriptor.Value,
                    Remarks = descriptor.Remarks
                };

                var entity = _repository.GetByKey(descriptor.Key, ConfigType.Module).Result;
                if (entity == null)
                {
                    _repository.AddAsync(newEntity, uow).GetAwaiter().GetResult();
                }
                else
                {
                    newEntity.Id = entity.Id;
                    _repository.UpdateAsync(newEntity, uow).GetAwaiter().GetResult();
                }
            }
        }
コード例 #2
0
        public async Task Save(List <ModuleOptionDescriptor> descriptors)
        {
            if (descriptors == null || !descriptors.Any())
            {
                return;
            }

            using var uow = _dbContext.NewUnitOfWork();
            foreach (var descriptor in descriptors)
            {
                var newEntity = new ConfigEntity
                {
                    Type    = ConfigType.Module,
                    Key     = descriptor.Key,
                    Value   = descriptor.Value,
                    Remarks = descriptor.Remarks
                };

                var entity = await _repository.GetByKey(descriptor.Key, ConfigType.Module);

                if (entity == null)
                {
                    await _repository.AddAsync(newEntity, uow);
                }
                else
                {
                    newEntity.Id = entity.Id;
                    await _repository.UpdateAsync(newEntity, uow);
                }
            }
        }
コード例 #3
0
        public async Task Add(ConfigDescriptor descriptor)
        {
            if (descriptor == null)
            {
                return;
            }

            await _repository.AddAsync(new ConfigEntity
            {
                Key     = descriptor.Key,
                Value   = descriptor.Value,
                Remarks = descriptor.Remarks
            });
        }
コード例 #4
0
        public async Task UpdateAsync(NdmConfig config)
        {
            if (!_config.StoreConfigInDatabase)
            {
                return;
            }

            var existingConfig = await _repository.GetAsync(config.Id);

            if (existingConfig is null)
            {
                await _repository.AddAsync(config);

                return;
            }

            await _repository.UpdateAsync(config);
        }
コード例 #5
0
        public async Task <IResultModel> Add(ConfigAddModel model)
        {
            if (await _repository.Exists(model.Key))
            {
                return(ResultModel.HasExists);
            }

            var entity = new ConfigEntity
            {
                Key     = model.Key,
                Value   = model.Value,
                Remarks = model.Remarks
            };

            var result = await _repository.AddAsync(entity);

            return(ResultModel.Result(result));
        }
コード例 #6
0
        public async Task <bool> SaveJson(ConfigType type, string code, string json)
        {
            if (code.IsNull())
            {
                throw new NullReferenceException("编码不能为空");
            }

            var entity = await _repository.Get(type, code) ?? new ConfigEntity();

            entity.Type  = type;
            entity.Code  = code;
            entity.Value = json;

            if (entity.Id > 0)
            {
                return(await _repository.UpdateAsync(entity));
            }

            return(await _repository.AddAsync(entity));
        }
コード例 #7
0
 public async Task <Config> Add(Config input)
 {
     return(await _configRepository.AddAsync(input));
 }