public async Task <List <Setting> > GetSettingsAsync(string application = null, string currentEnvironment = null) { try { Expression <Func <SettingEF, bool> > filter = s => true; if (!string.IsNullOrEmpty(application)) { if (string.IsNullOrEmpty(currentEnvironment)) { filter = s => s.Application == application; } else { filter = s => s.Application == application && s.Environment == currentEnvironment; } } using (var context = new SettingsContext(this.ConnectionString)) { List <SettingEF> results = await context.Settings.Where(filter) .ToListAsync() .ConfigureAwait(false); return(StoredSettingMapper.Map(results).ToList()); } } catch (Exception exp) { logger.Warn(string.Format("Error getting settings from EF for the app {0} and env {1}", application, currentEnvironment), exp); throw; } }
public async Task <List <Setting> > GetSettingsAsync(string application = null, string currentEnvironment = null) { try { Expression <Func <SettingMongo, bool> > filterExpression = s => true; if (!string.IsNullOrEmpty(application)) { if (string.IsNullOrEmpty(currentEnvironment)) { filterExpression = s => s.Application == application; } else { filterExpression = s => s.Application == application && s.Environment == currentEnvironment; } } var filter = Builders <SettingMongo> .Filter.Where(filterExpression); var result = await this.SettingsCollection.FindAsync <SettingMongo>(filter).ConfigureAwait(false); return(StoredSettingMapper.Map(await result.ToListAsync().ConfigureAwait(false)).ToList()); } catch (Exception exp) { logger.Warn(string.Format("Error getting settings from mongo for the app {0} and env {1}", application, currentEnvironment), exp); throw; } }
public async Task AddSettingAsync(Setting setting) { try { SettingMongo settingMongo = StoredSettingMapper.Map <SettingMongo>(setting); settingMongo.Created = settingMongo.Updated = DateTimeOffset.UtcNow; await this.SettingsCollection.InsertOneAsync(settingMongo).ConfigureAwait(false); } catch (Exception exp) { logger.Warn(string.Format("Error adding setting {0} to mongo", Newtonsoft.Json.JsonConvert.SerializeObject(setting)), exp); throw; } }
public async Task AddSettingAsync(Setting setting) { try { using (var context = new SettingsContext(this.ConnectionString)) { SettingEF settingToAdd = StoredSettingMapper.Map <SettingEF>(setting); settingToAdd.Created = settingToAdd.Updated = DateTimeOffset.UtcNow; context.Settings.Add(settingToAdd); await context.SaveChangesAsync().ConfigureAwait(false); } } catch (Exception exp) { logger.Warn(string.Format("Error adding setting {0} to EF", Newtonsoft.Json.JsonConvert.SerializeObject(setting)), exp); throw; } }
public async Task <Setting> GetSettingAsync(string id) { try { var filter = Builders <SettingMongo> .Filter.Where(s => s.DbId == new ObjectId(id)); var result = await this.SettingsCollection.Find <SettingMongo>(filter) .SingleOrDefaultAsync() .ConfigureAwait(false); return(StoredSettingMapper.Map(result)); } catch (Exception exp) { logger.Warn(string.Format("Error getting with id {0} from EF", id), exp); throw; } }
public async Task UpdateSettingAsync(string id, Setting value) { try { SettingMongo settingMongo = StoredSettingMapper.Map <SettingMongo>(value); var filter = Builders <SettingMongo> .Filter.Eq(s => s.DbId, new ObjectId(id)); var update = Builders <SettingMongo> .Update.Set(s => s.JSONValue, settingMongo.JSONValue) .Set(s => s.Documentation, settingMongo.Documentation) .Set(s => s.Updated, DateTimeOffset.UtcNow); await this.SettingsCollection.UpdateOneAsync(filter, update).ConfigureAwait(false); } catch (Exception exp) { logger.Warn(string.Format("Error while updating setting {0} into mongo", Newtonsoft.Json.JsonConvert.SerializeObject(value)), exp); throw; } }
public async Task <Setting> GetSettingAsync(string id) { try { using (var context = new SettingsContext(this.ConnectionString)) { long lId; if (long.TryParse(id, out lId)) { SettingEF result = await context.Settings.FirstOrDefaultAsync(s => s.DbId == lId) .ConfigureAwait(false); return(StoredSettingMapper.Map(result)); } return(null); } } catch (Exception exp) { logger.Warn(string.Format("Error getting setting with id {0} from mongo", id), exp); throw; } }
public async Task UpdateSettingAsync(string id, Setting value) { try { using (var context = new SettingsContext(this.ConnectionString)) { SettingEF settingMapped = StoredSettingMapper.Map <SettingEF>(value); SettingEF settingEF = await context.Settings.Where(s => s.Id == id).FirstOrDefaultAsync().ConfigureAwait(false); if (settingEF != null) { settingEF.JSONValue = settingMapped.JSONValue; settingEF.Documentation = settingMapped.Documentation; settingEF.Updated = DateTimeOffset.UtcNow; await context.SaveChangesAsync().ConfigureAwait(false); } } } catch (Exception exp) { logger.Warn(string.Format("Error while updating setting {0} in EF", Newtonsoft.Json.JsonConvert.SerializeObject(value)), exp); throw; } }