public IActionResult UpdateBet(string id, [FromBody] Bet bet) { if (bet == null) { return(BadRequest()); } db.UpdateBet(bet, id); return(Created("Created", bet)); }
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)); }