public async Task <IActionResult> Onpost() { if (ModelState.IsValid) { GameEngine.Game gameEngine = new GameEngine.Game(_context); gameEngine.Settings = new GameSettings(); gameEngine.InitializeNewBoard(Options.BoardWidth, Options.BoardHeight); var entity = new Domain.GameSave() { SaveName = Options.SaveName, BoardHeight = Options.BoardHeight, BoardWidth = Options.BoardWidth, NumberOfMines = Options.NumberOfMines, BoardState = gameEngine.GetSerializedGameState() }; _context.GameSave.Add(entity); await _context.SaveChangesAsync(); return(RedirectToPage("./PlayGame", new{ GameId = entity.GameSaveId })); } return(Page()); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(GameSave).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GameSaveExists(GameSave.GameSaveId)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.GameSave.Add(GameSave); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } GameSave = await _context.GameSave.FindAsync(id); if (GameSave != null) { _context.GameSave.Remove(GameSave); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public ActionResult OnPost() { if (ModelState.IsValid) { var savedGames = new List <string>(); foreach (var gameSave in _context.GameSave) { savedGames.Add(gameSave.SaveName); } if (savedGames.Contains(SaveFileName)) { return(RedirectToPage(new { dif = Difficulty, SaveFileName })); } GameEngine.Game gameEngine = new GameEngine.Game(_context); //you need to fix the functions, maybe remove them entirely. switch (Difficulty) { case "1": gameEngine.Settings = new GameSettings(); break; case "2": gameEngine.Settings = new GameSettings() { BoardHeight = 16, BoardWidth = 16, NumberOfMines = 40 }; break; case "3": gameEngine.Settings = new GameSettings() { BoardHeight = 24, BoardWidth = 24, NumberOfMines = 99 }; break; default: gameEngine.Settings = new GameSettings(); break; } gameEngine.InitializeNewBoard(gameEngine.Settings.BoardWidth, gameEngine.Settings.BoardHeight); var entity = new Domain.GameSave() { SaveName = gameEngine.Settings.SaveName, BoardHeight = gameEngine.Settings.BoardHeight, BoardWidth = gameEngine.Settings.BoardWidth, NumberOfMines = gameEngine.Settings.NumberOfMines, BoardState = gameEngine.GetSerializedGameState() }; _context.GameSave.Add(entity); _context.SaveChangesAsync(); return(RedirectToPage("./PlayGame", new { GameId = entity.GameSaveId })); } return(RedirectToPage("../Index")); }