public async Task SaveSettingsAsync(SettingsModel settings) { var defaultNumberPrefixSetting = await _settingRepository.GetByKeyAsync(DataConstants.SettingDefaultNumberPrefixKey); if (defaultNumberPrefixSetting == null) { defaultNumberPrefixSetting = new Setting { Key = DataConstants.SettingDefaultNumberPrefixKey, Value = settings.NumberPrefix.Id.ToString() }; await _settingRepository.AddAsync(defaultNumberPrefixSetting); } else { defaultNumberPrefixSetting.Value = settings.NumberPrefix.Id.ToString(); await _settingRepository.UpdateAsync(defaultNumberPrefixSetting); } }
public async Task <Setting> GetByKeyAsync(string key) { var rs = (await DALHelper.Query <Setting>($"SELECT * FROM `setting` WHERE `name` = '{key}'", dbTransaction: DbTransaction, connection: DbConnection)) .FirstOrDefault(); if (rs == null) { rs = new Setting() { Name = key, Value = "", Description = "", CreatedBy = 0, CreatedDate = DateTime.Now, ModifiedBy = 0, ModifiedDate = DateTime.Now, }; rs.Id = await _settingRepository.AddAsync(rs); } return(rs); }
public override async Task <int> HandleCommand(InsertSettingCommand request, CancellationToken cancellationToken) { var id = 0; using (var conn = DALHelper.GetConnection()) { conn.Open(); using (var trans = conn.BeginTransaction()) { try { request.Model.CreatedDate = DateTime.Now; request.Model.CreatedBy = request.LoginSession.Id; request.Model.ModifiedDate = DateTime.Now; request.Model.ModifiedBy = request.LoginSession.Id; id = await settingRepository.AddAsync(request.Model); } catch (Exception ex) { throw ex; } finally { if (id > 0) { trans.Commit(); } else { try { trans.Rollback(); } catch { } } } } } return(id); }