Beispiel #1
0
        public IActionResult CloseRouletteBets(string id)
        {
            var seed               = Environment.TickCount;
            var random             = new Random(seed);
            var roulette           = db.GetRouletteById(id);
            var bets               = dbBet.GetAllBets(id);
            var NumberRandomResult = random.Next(0, 36);
            var colorRandomResult  = random.Next(0, 1);

            foreach (var bet in bets)
            {
                if (bet.betNumber == NumberRandomResult && string.IsNullOrEmpty(bet.betColor))
                {
                    bet.isWinner = true;
                }

                if (bet.betColor == "red" && colorRandomResult == 0)
                {
                    bet.isWinner = true;
                }

                if (bet.betColor == "black" && colorRandomResult == 1)
                {
                    bet.isWinner = true;
                }

                if (bet.isWinner)
                {
                    var betUser = dbUser.GetUsersById(bet.idUser);
                    if (betUser != null)
                    {
                        betUser.credit += bet.moneyValue * 2;
                        dbUser.UpdateUsers(betUser, betUser.id);
                        dbBet.UpdateBet(bet, bet.id);
                    }
                }
            }
            roulette.state = "close";
            db.UpdateRoulette(roulette, roulette.id);

            return(Ok(bets));
        }
Beispiel #2
0
 public IActionResult GetAllBets()
 {
     return(Ok(db.GetAllBets()));
 }