Exemple #1
0
        public async Task <bool> UpdateRoundPlayer(string id, [FromBody] RoundPlayerServiceViewModel viewModel)
        {
            if (id == viewModel.Id)
            {
                var isUpdated = await _roundPlayerService.UpdateRoundPlayer(viewModel);

                return(isUpdated);
            }
            return(false);
        }
Exemple #2
0
        public static RoundPlayerServiceViewModel Map(RoundPlayer entity)
        {
            var viewModel = new RoundPlayerServiceViewModel()
            {
                Id       = entity.Id.ToString(),
                RoundId  = entity.RoundId.ToString(),
                PlayerId = entity.PlayerId.ToString(),
                Bet      = entity.Bet,
                Cards    = entity.Cards
            };

            return(viewModel);
        }
        private int CountScore(RoundPlayerServiceViewModel roundPlayer)
        {
            try
            {
                var score = 0;
                var aces  = 0;

                var Cards = JsonConvert.DeserializeObject <List <CardLogic> >(roundPlayer.Cards);
                foreach (var card in Cards)
                {
                    if (!Enum.TryParse(card.value.ToString("g"), out ScoreLogic cardScore))
                    {
                        Logger.WriteLogToFile("Could not parse card", "GameLogicService", "CountScore");
                        return(0);
                    }

                    if ((int)cardScore != 1)
                    {
                        score += (int)cardScore;
                    }
                    else
                    {
                        aces++;
                    }
                }

                for (var i = 0; i < aces; i++)
                {
                    if (score <= 21 - (aces + score))
                    {
                        score += 11;
                    }
                    else
                    {
                        score++;
                    }
                }

                return(score);
            }
            catch (Exception ex) {
                Logger.WriteLogToFile(ex.Message, "GameLogicService", "CountScore");
            }
            return(0);
        }
        public async Task <int> DeleteRoundPlayer(RoundPlayerServiceViewModel viewModel)
        {
            try
            {
                var entity = DataMapper.Map(viewModel);
                if (entity.Id != Guid.Empty && entity.RoundId != Guid.Empty && entity.PlayerId != Guid.Empty)
                {
                    var result = await _roundPlayerRepository.Remove(entity);

                    return(result);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLogToFile(ex.Message, "RoundPlayerService", "DeleteRoundPlayer");
            }
            return(0);
        }
Exemple #5
0
        public static RoundPlayer Map(RoundPlayerServiceViewModel viewModel)
        {
            if (Guid.TryParse(viewModel.Id, out Guid id) && Guid.TryParse(viewModel.RoundId, out Guid roundId) && Guid.TryParse(viewModel.PlayerId, out Guid playerId))
            {
                var entity = new RoundPlayer()
                {
                    Id       = id,
                    RoundId  = roundId,
                    PlayerId = playerId,
                    Bet      = viewModel.Bet,
                    Cards    = viewModel.Cards
                };

                return(entity);
            }

            return(new RoundPlayer {
                Id = Guid.Empty,
                PlayerId = Guid.Empty,
                RoundId = Guid.Empty
            });
        }