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(); } }
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(); } }
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()); }
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; } }
/// <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); } }
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)); }
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); } }
public bool AddOrUpdate(Setting entity) { try { if (entity.Id > 0) { _settingRepository.Update(entity); } else { _settingRepository.Add(entity); } return(true); } catch (Exception ex) { return(false); } }
public Setting Create(Setting Setting) { return(_settingRepository.Add(Setting)); }
public void CreateSetting(Setting setting) { settingRepository.Add(setting); }
public void CreateSetting(Setting Setting) { SettingRepository.Add(Setting); }
public void CreateSetting(Setting faq) { faqRepository.Add(faq); SaveSetting(); }