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 SetAsync(GlobalConfigItems key, string value) { if (string.Equals(value, "null", StringComparison.InvariantCultureIgnoreCase)) { value = null; } await ConfigurationService.SetValueAsync(key, value); await ReplyAsync("Konfigurace uložena"); }
public async Task GetAsync(GlobalConfigItems key) { var value = ConfigurationService.GetValue(key); if (string.IsNullOrEmpty(value)) { value = "null"; } if (value.Length >= Discord.DiscordConfig.MaxMessageSize) { using var stream = new MemoryStream(Encoding.UTF8.GetBytes(value)); await Context.Channel.SendFileAsync(stream, $"{key}.txt"); return; } await ReplyAsync($"```\n{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()]); }