private async Task HandleCustomCommandDeleteAsync(string key) { CustomCommand cc = _db.CustomCommands.FirstOrDefault(x => x.Command == key); if (cc != null) { _db.Remove(cc); await _db.SaveChangesAsync(); await Context.Channel.SendMessageAsync($"Custom Command: {key} was deleted.").ConfigureAwait(false); } else { await Context.Channel.SendMessageAsync($"Custom Command: {key} does not exist").ConfigureAwait(false); } }
private async Task HandleConfigSubCommandAsync(string sub, string key, string value) { DBConfigSettings config = _db.ConfigSettings.FirstOrDefault(config => config.Subsection == sub && config.Key == key); if (config != null) { if (string.IsNullOrEmpty(value)) { _db.Remove(config); await Context.Channel.SendMessageAsync("Deleted DB Setting"); await _db.SaveChangesAsync().ConfigureAwait(false); return; } config.Value = value; _db.Entry(config).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } else { if (string.IsNullOrEmpty(value)) { await Context.Channel.SendMessageAsync("New DB Setting cannot have blank value.\r\n" + "Syntax: !config section key value\r\n" + "Example: !config Channels Log #test-channel"); return; } config = new DBConfigSettings { Subsection = sub, Key = key, Value = value }; _db.ConfigSettings.Add(config); } await _db.SaveChangesAsync().ConfigureAwait(false); await Context.Channel.SendMessageAsync("Updated DB Setting"); }