public IActionResult OnGetSaveGame() { var game = DeSerializeGame(); if (SavedGameId == null) { SavedGameHandler.SaveGame(game); } else { var existingSavedGame = GetSavedGames().First(sg => sg.SavedGameId == SavedGameId); SavedGameHandler.SaveGame(game, existingSavedGame); } return(Redirect("./Game")); }
private static void SaveGame(Game game) { if (game.GameStatus == GameStatus.NotStarted) { Console.WriteLine("Please make the first move before saving!"); return; } var saveActionMenu = new Menu() { Title = "Save Game", MenuItemsDictionary = new Dictionary <string, MenuItem>() { { "1", new MenuItem() { Title = "Save a new game", CommandToExecute = () => SaveGame(false) } }, { "2", new MenuItem() { Title = "Overwrite an existing saved game", CommandToExecute = () => SaveGame(true) } } } }; String SaveGame(Boolean overrideExistingSave) { var saveGameSelectMenu = new Menu(); if (overrideExistingSave) { var savedGames = SavedGameHandler.GetSavedGames(); if (!savedGames.Any()) { Console.WriteLine("No saved games found!"); return(""); } var i = 1; foreach (var existingSavedGame in savedGames) { saveGameSelectMenu.addMenuItem(i.ToString(), new MenuItem() { Title = existingSavedGame.DateTime.ToString(), CommandToExecute = () => { SavedGameHandler.SaveGame(game, existingSavedGame); return("X"); } }); i++; } return(saveGameSelectMenu.Run()); } SavedGameHandler.SaveGame(game); return("X"); } saveActionMenu.Run(); }