public async Task SetValueAsync(GlobalConfigItems key, string data) { Configuration[key.ToString()] = data; using var scope = ServiceProvider.CreateScope(); using var repository = scope.ServiceProvider.GetService <IGrillBotRepository>(); var item = await repository.GlobalConfigRepository.GetItemAsync(key); if (item == null) { item = new GlobalConfigItem() { Key = key.ToString(), Value = data }; await repository.AddAsync(item); } else { item.Value = data; } await repository.CommitAsync(); }
public async Task <string> GetItemAsync(GlobalConfigItems itemKey) { var key = itemKey.ToString(); var result = await Context.GlobalConfig .SingleOrDefaultAsync(o => o.Key == key); return(result?.Value); }
public async Task UpdateItemAsync(GlobalConfigItems item, string value) { var key = item.ToString(); var result = await Context.GlobalConfig .SingleOrDefaultAsync(o => o.Key == key); if (result == null) { result = new GlobalConfigItem() { Key = key, Value = value }; Context.GlobalConfig.Add(result); } else { result.Value = value; } await Context.SaveChangesAsync(); }
public Task <GlobalConfigItem> GetItemAsync(GlobalConfigItems key) { return(Context.GlobalConfig.AsQueryable() .SingleOrDefaultAsync(o => o.Key == key.ToString())); }
public string GetValue(GlobalConfigItems key) { return(Configuration[key.ToString()]); }