Exemple #1
0
        public async Task <Response> CloseRoulette(string id)
        {
            List <Bet>           betList        = null;
            List <UserBetResult> userBetResults = null;
            Roulette             roulette       = null;
            byte      WinnerNumber = 0;
            Response  response     = new Response();
            BetResult betResult    = null;

            roulette = await Context.GetRoulette(id);

            response = ValidateForCloseRoulette(roulette);
            if (!response.Successfull)
            {
                return(response);
            }
            betList = await Context.GetBetsFromRoulette(id);

            if (betList == null || betList.Count <= 0)
            {
                return(new Response(false, "ERROR: There is not any bet on this roulette!", null));
            }
            WinnerNumber   = NumbersUtil.RandomByte(36);
            userBetResults = ConvertToUserBetResults(WinnerNumber, betList);
            response       = await PerformRouletteClosingOnDB(roulette);

            if (!response.Successfull)
            {
                return(new Response(false, "ERROR: Could not close roulette!", null));
            }
            betResult = new BetResult()
            {
                BetsPerformed        = betList,
                UsersBetResults      = userBetResults,
                WinnerNumberAndColor = $"{BetUtils.GetBetColorFromByte(WinnerNumber)} {WinnerNumber}",
            };

            return(new Response(true, $"Roulette was closed successfully", betResult));
        }
Exemple #2
0
        protected List <UserBetResult> ConvertToUserBetResults(byte WinnerNumber, List <Bet> betList)
        {
            UserBetResult        resultBet;
            List <UserBetResult> userBetResults = new List <UserBetResult>();
            decimal moneyGained   = 0;
            string  winnerOrLoser = "";

            foreach (var bet in betList)
            {
                moneyGained   = ComputeWinnerGain(WinnerNumber, bet);
                winnerOrLoser = moneyGained <= 0 ? $"lost ${bet.Bet_Amount}" : $"gained ${moneyGained - bet.Bet_Amount} (${moneyGained})";
                resultBet     = new UserBetResult()
                {
                    Bet_Description     = $"User betted ${bet.Bet_Amount} for {BetUtils.ComposeBetInfo(bet)} and { winnerOrLoser }",
                    UserBet_GainedMoney = moneyGained,
                    User_Id             = bet.User_Id,
                    Bet_Id = bet.Bet_Id
                };
                userBetResults.Add(resultBet);
            }
            return(userBetResults);
        }