public Entities.ActionResponses.PlayCard Execute(List<Int32> cardIDs, Int32 gameID, Int32 userId, Boolean autoPlayed)
{
Entities.ActionResponses.PlayCard playResponse = new Entities.ActionResponses.PlayCard();
List<Entities.GamePlayerCard> cards = _selectGamePlayerCard.Execute(gameID, userId);
//Check that the user did not play cards they do not have
List<Int32> missedIds = CheckHand(cards, cardIDs);
if (missedIds.Count == 0)
{
Entities.GameRound round = _selectGameRound.Execute(gameID, true);
//Validate the user isn't trying to answer multiple times
if (round.HasAnswer(userId) == false)
{
//Validate the correct number of cards were played
if (round.ValidateCardPlayedCount(cardIDs.Count))
{
//Create GameRoundCards for played cards
List<Entities.GameRoundCard> playedCards = CreateRoundCards(cardIDs, userId, round.GameRoundID, gameID, autoPlayed);
//Insert playedCards
_insertGameRoundCard.Execute(playedCards);
if (autoPlayed)
{
playResponse.AutoPlayedSuccess = true;
}
//Select round with game cards
round = _selectGameRound.Execute(gameID, true);
//Remove cards from player's hand
_deleteGamePlayerCard.Execute(cardIDs, gameID, userId);
playResponse.CurrentRound = round;
playResponse.ResponseCode = Entities.ActionResponses.Enums.PlayCardResponseCode.Success;
}
else
{
playResponse.ResponseCode = Entities.ActionResponses.Enums.PlayCardResponseCode.InvalidNumberOfCardsPlayed;
}
}
else
{
playResponse.CurrentRound = round;
playResponse.ResponseCode = Entities.ActionResponses.Enums.PlayCardResponseCode.Success;
}
}
else
{
playResponse.ResponseCode = Entities.ActionResponses.Enums.PlayCardResponseCode.InvalidCardPlayed;
}
return playResponse;
}