public void DiscardCards(ReplaceCardModel cards) { int handID = GetHandID(cards.TableId); if (cards.Discards == null) { cards.Discards = new List <Card>(); } try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); foreach (Card card in cards.Discards) { SqlCommand cmd = new SqlCommand("DELETE FROM hand_cards WHERE hand_id = @handID AND player = @player AND card_suit = @suit AND card_number = @number;", conn); cmd.Parameters.AddWithValue("@handID", handID); cmd.Parameters.AddWithValue("@player", cards.Username); cmd.Parameters.AddWithValue("@suit", card.Suit); cmd.Parameters.AddWithValue("@number", card.Number); cmd.ExecuteNonQuery(); } } } catch (SqlException) { throw; } }
public ActionResult ReplaceCards(ReplaceCardModel model) { TableSqlDal dal = new TableSqlDal(); int handID = dal.GetHandID(model.TableId); Table table = GetTableInfo(model.TableId); dal.SetPlayerToHasChecked(model.TableId, handID, model.Username); dal.SetCurrentBet(model.TableId, model.Username); dal.DiscardCards(model); dal.DrawCards(handID, model.Discards.Count, model.Username); table = GetTableInfo(model.TableId); UpdatePlayerTurn(model.TableId); int i = 0; foreach (Seat s in table.Seats) { if (s.Username == "Available") { i++; } else if (s.HasChecked || s.HasFolded) { i++; } } if (i == 5) { table.StateCounter++; dal.UpdateStateCounter(model.TableId); dal.UncheckAllPlayer(model.TableId); return(RedirectToAction("AdvanceGame", new { tableID = model.TableId })); } return(RedirectToAction("HandSetup", new { tableID = model.TableId })); }