public async Task <bool> RemoveBinding(IEntity <ulong> binding) { using (var db = new BotFunctionSpamContext(dbOptions)) { var entities = db.BotFunctionSpamBindings.Where(b => b.ChannelId == binding.Id); if (!entities.Any()) { return(false); } db.BotFunctionSpamBindings.RemoveRange(entities); await db.SaveChangesAsync(); return(true); } }
public async Task <bool> AddBinding(IMessageChannel channel) { using (var db = new BotFunctionSpamContext(dbOptions)) { if (db.BotFunctionSpamBindings.Any(b => b.ChannelId == channel.Id)) { return(false); } db.BotFunctionSpamBindings.Add(new BotFunctionSpamBinding { ChannelId = channel.Id, }); await db.SaveChangesAsync(); return(true); } }
public bool CheckBinding(IMessageChannel channel) { using (var db = new BotFunctionSpamContext(dbOptions)) return(db.BotFunctionSpamBindings.All(b => b.ChannelId != channel.Id)); }