// [HttpGet("clear")] public RedirectToActionResult EndGame() { // set players to inactive // deleting players for now // Player playerOne = dbContext.Players.FirstOrDefault(p => p.PlayerState == 1); // Player playerTwo = dbContext.Players.FirstOrDefault(p => p.PlayerState == 2); // dbContext.Players.Remove(playerOne); // dbContext.Players.Remove(playerTwo); List <Player> allPlayers = dbContext.Players.ToList(); foreach (Player x in allPlayers) { dbContext.Remove(x); } List <Ship> allShips = dbContext.Ships.ToList(); foreach (Ship ship in allShips) { dbContext.Remove(ship); } dbContext.SaveChanges(); // big stuff. HttpContext.Session.Clear(); return(RedirectToAction("Intro", "Home")); }
public IActionResult GameOver() { // ViewBag.EndGameTally = HttpContext.Session.GetInt32("CombatLog"); ViewBag.EndGameTally = dbContext.LightYearDebug.OrderByDescending(ly => ly.LightYearDebuggerId).FirstOrDefault(); List <Ship> allShips = dbContext.Ships.ToList(); GameState GS = dbContext.Instances.FirstOrDefault(g => g.GameId == HttpContext.Session.GetInt32("GameId")); ViewBag.gameState = GS; foreach (Ship ship in allShips) { dbContext.Remove(ship); } dbContext.SaveChanges(); return(View("GameOverMan")); }