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