private static void AddTestData(PokerTableContext context) { var table = new PokerTable { TableState = TableStates.Registering }; context.PokerTables.Add(table); context.SaveChanges(); var player1 = new Player { Name = "Player1", Token = Guid.NewGuid(), HoleCards = "AsAd", TableId = table.Id }; context.Players.Add(player1); var player2 = new Player { Name = "Player2", Token = Guid.NewGuid(), HoleCards = "KsKd", TableId = table.Id }; context.Players.Add(player2); context.SaveChanges(); }
public IActionResult Create([FromBody] PokerTable item) { if (item == null) { return(BadRequest()); } _context.PokerTables.Add(item); _context.SaveChanges(); return(CreatedAtRoute("GetPokerTable", new { id = item.Id }, item)); }
public IActionResult Post([FromBody] Player player, int tableId) { if (player == null || tableId == 0) { return(BadRequest()); } if (!_tableContext.PokerTables.Any(t => t.Id == tableId)) { return(BadRequest()); // This table Id doesn't exist } player.Token = Guid.NewGuid(); player.TableId = tableId; //_tableContext.PokerTables.Single(t => t.Id == tableId); //_playerContext.Players.Add(player); //_playerContext.SaveChanges(); _tableContext.Players.Add(player); _tableContext.SaveChanges(); return(CreatedAtRoute("GetPlayer", new { id = player.Id }, player)); }