public async Task <IActionResult> CreateGame([FromBody] Game g) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var game = await _context.Game.FindAsync(g.gameID); if (game != null) { return(Ok(game)); } else { var new_game = new Game { gameID = g.gameID, player1 = g.player1, player2 = null, board = "[0,0,0,0,0,0,0,0,0]", watchers = 0, turn = 0, p1_timestamp = g.p1_timestamp, p2_timestamp = 0, winner = 0, // 0 = not started, 1 = player1, 2 = player2, 3 = draw }; _context.Game.Add(new_game); await _context.SaveChangesAsync(); return(Ok(new_game)); } }
public async Task <IActionResult> PostAuth([FromBody] Auth auth) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (auth.playerName != null) { var q = await _context.Auth.Where(x => x.playerName == auth.playerName).FirstOrDefaultAsync(); if (q != null) { if (q.passcode == auth.passcode) // Correct passcode { return(Ok(q)); } else // Incorrect passcode { q.passcode = null; return(Ok(q)); } } else // Create account { auth.playerID = Guid.NewGuid().ToString(); var p = new Player { playerID = auth.playerID, playerName = auth.playerName, mmr = 0, wins = 0, games = 0 }; _context.Player.Add(p); _context.Auth.Add(auth); await _context.SaveChangesAsync(); return(Ok(auth)); } } return(Ok()); }