public async Task <IActionResult> DeleteConfirmed(int id) { var channelModel = await _context.Channels.FindAsync(id); _context.Entry(channelModel).Reference(channel => channel.Server).Load(); var test = channelModel.Server; var serverId = channelModel.ServerModelId; var bot = _runningBots.Find(x => (x.Channel == channelModel.ChannelName) && (x.Username == channelModel.Server.Username) && (x.Server == channelModel.Server.Host)); if (bot != null) { bot.Disconnect(); _runningBots.Remove(bot); bot = null; } _context.Channels.Remove(channelModel); await _context.SaveChangesAsync(); return(RedirectToAction("Edit", "Servers", new { Id = serverId })); }