コード例 #1
0
        private async Task <RoundGameView> MappingToViewModel(List <Round> rounds)
        {
            var result         = rounds.GroupBy(p => p.Player.Name);
            var roundViewModel = new RoundGameView();

            foreach (var round in result)
            {
                var userModel = new PlayerNextRoundViewItem();
                userModel.UserName = round.Key;

                foreach (var item in round)
                {
                    var         cardViewModel = new CardGameViewItem();
                    PlayerGames playerGames   = await GetPlayerStatus(item.PlayerId, item.GameId);

                    userModel.PlayerId     = item.PlayerId;
                    userModel.GameId       = item.GameId;
                    userModel.PlayerRole   = (PlayerRoleEnumView)item.Player.PlayerRole;
                    userModel.PlayerStatus = (PlayerStatusEnumView)playerGames.Status;

                    cardViewModel.Rank  = item.Card.Rank.ToString();
                    cardViewModel.Suit  = item.Card.Suit.ToString();
                    cardViewModel.Value = item.Card.Value;
                    userModel.CardSum  += item.Card.Value;

                    userModel.Cards.Add(cardViewModel);
                }
                roundViewModel.Users.Add(userModel);
            }
            roundViewModel.GameId = rounds[0].GameId;

            return(roundViewModel);
        }
コード例 #2
0
        private async Task CreateNextRoundForDealer(PlayerNextRoundViewItem dealer)
        {
            var round = new Round();
            var card  = new Card();

            card = await _cardRepository.GetRandom();

            round.PlayerId = dealer.PlayerId;
            round.GameId   = dealer.GameId;
            round.CardId   = card.Id;

            var cardViewModel = new CardGameViewItem();

            cardViewModel.Rank  = card.Rank.ToString();
            cardViewModel.Suit  = card.Suit.ToString();
            cardViewModel.Value = card.Value;

            dealer.CardSum += card.Value;

            dealer.Cards.Add(cardViewModel);
            await _roundRepository.Add(round, round.GameId);
        }