示例#1
0
        private async Task LoadSettingsAsync(Setting[] settings)
        {
            if (settings != null)
            {
                foreach (var setting in settings)
                {
                    var existingSetting = await _settingRepository.GetAsync(setting.Id);

                    if (existingSetting == null)
                    {
                        if (string.IsNullOrEmpty(setting.CreatedDate))
                        {
                            setting.CreatedDate = DateTimeOffset.UtcNow.ToString("s");
                        }
                        _settingRepository.Add(setting);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(setting.CreatedDate) && setting.CreatedDate.CompareTo(existingSetting.CreatedDate) > 0)
                        {
                            existingSetting.Type  = setting.Type;
                            existingSetting.Key   = setting.Key;
                            existingSetting.Value = setting.Value;
                            _settingRepository.Update(existingSetting);
                        }
                    }
                }

                await _settingRepository.SaveChangesAsync();
            }
        }
示例#2
0
        public void SetSetting <T>(SettingKeys key, T val)
        {
            var setting = _settingRepository.FindBy(t => t.Key == key.ToString()).FirstOrDefault();

            if (setting != null)
            {
                setting.Value = JsonSerializer <T>(val);
                _settingRepository.Commit();
            }
            else
            {
                var newSetting = new Setting();
                newSetting.Key   = key.ToString();
                newSetting.Value = JsonSerializer <T>(val);
                _settingRepository.Add(newSetting);
                _settingRepository.Commit();
            }
        }
示例#3
0
        public async Task <IActionResult> AddSetting([FromBody] SettingDto settingDto)
        {
            Setting setting = new Setting((SettingType)settingDto.Type,
                                          settingDto.Code, settingDto.Name, settingDto.IsComputing, settingDto.Description);
            await settingRepository.Add(setting);

            await unitOfWork.SaveEntitiesAsync();

            return(Ok());
        }
示例#4
0
 public async Task <bool> AddSetting(SettingDTO model)
 {
     try
     {
         var setting = _mapper.Map <Setting>(model);
         _repoSetting.Add(setting);
         return(await _repoSetting.SaveAll());
     }
     catch (System.Exception)
     {
         throw;
     }
 }
示例#5
0
        /// <summary>
        /// Adds a setting
        /// </summary>
        /// <param name="setting">Setting</param>
        /// <param name="clearCache">A value indicating whether to clear cache after setting update</param>
        public virtual void InsertSetting(Setting setting, bool clearCache = true)
        {
            if (setting == null)
            {
                throw new ArgumentNullException("setting");
            }

            _settingRepository.Add(setting);
            Save();
            //cache
            if (clearCache)
            {
                _cacheManager.RemoveByPattern(SETTINGS_PATTERN_KEY);
            }
        }
示例#6
0
        public async Task <Result <Unit> > Handle(UpdateDateTimeSettingCommand request, CancellationToken cancellationToken)
        {
            var setting = await _settingRepository.GetByCodeAsync(request.SettingCode);

            if (setting == null)
            {
                setting = new Setting(_plantProvider.Plant, request.SettingCode);
                _settingRepository.Add(setting);
            }

            setting.SetDateTime(request.Value);

            await _unitOfWork.SaveChangesAsync(cancellationToken);

            return(new SuccessResult <Unit>(Unit.Value));
        }
示例#7
0
        public void SaveSettings(SettingsModel settings)
        {
            var defaultNumberPrefixSetting = _settingRepository.GetByKey(DataConstants.SettingDefaultNumberPrefixKey);

            if (defaultNumberPrefixSetting == null)
            {
                defaultNumberPrefixSetting = new Setting
                {
                    Key   = DataConstants.SettingDefaultNumberPrefixKey,
                    Value = settings.NumberPrefix.Id.ToString()
                };
                _settingRepository.Add(defaultNumberPrefixSetting);
            }
            else
            {
                defaultNumberPrefixSetting.Value = settings.NumberPrefix.Id.ToString();
                _settingRepository.Update(defaultNumberPrefixSetting);
            }
        }
示例#8
0
 public bool AddOrUpdate(Setting entity)
 {
     try
     {
         if (entity.Id > 0)
         {
             _settingRepository.Update(entity);
         }
         else
         {
             _settingRepository.Add(entity);
         }
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
示例#9
0
 public Setting Create(Setting Setting)
 {
     return(_settingRepository.Add(Setting));
 }
示例#10
0
 public void CreateSetting(Setting setting)
 {
     settingRepository.Add(setting);
 }
示例#11
0
 public void CreateSetting(Setting Setting)
 {
     SettingRepository.Add(Setting);
 }
示例#12
0
 public void CreateSetting(Setting faq)
 {
     faqRepository.Add(faq);
     SaveSetting();
 }