private async Task <List <BetResponse> > GetBetWinners(model.Roulette roulette)
        {
            List <BetResponse> listWin = new List <BetResponse>();
            var response = await BetServices.GetAllForRoulette(roulette);

            if (response.StatusCode == HttpStatusCode.OK.GetHashCode())
            {
                var listBet = (List <BetRequest>)response.Data;
                //Random rnd = new Random();
                var numWin = 10;//rnd.Next(0, 36);
                foreach (var bet in listBet.Where(x => x.Number != null))
                {
                    if (bet.Number == numWin)
                    {
                        var result = bet.GetBetResponse();
                        result.CashWin = result.Value * 5;
                        listWin.Add(result);
                    }
                }
                var color = numWin % 2 == 0 ? Color.Red : Color.Black;
                foreach (var bet in listBet.Where(x => x.Color != 0))
                {
                    if (bet.Color == color)
                    {
                        var result = bet.GetBetResponse();
                        result.CashWin = result.Value * 1.8;
                        listWin.Add(result);
                    }
                }
            }
            return(listWin);
        }
Beispiel #2
0
        public async Task <Response> GetAllForRoulette(model.Roulette roulette)
        {
            Response response = new Response();

            try
            {
                response.StatusCode = HttpStatusCode.OK.GetHashCode();
                response.Data       = await BetAdapter.GetBets(roulette.Id.ToString());
            }
            catch (Exception ex)
            {
                response.StatusCode = HttpStatusCode.Forbidden.GetHashCode();
                response.Errors.Add(new Entities.Utils.Error(response.StatusCode.ToString(), ex.Message));
            }
            return(response);
        }
        public async Task <Response> AddRoulette()
        {
            Response response = new Response();

            try
            {
                Random         rnd      = new Random();
                model.Roulette roulette = new model.Roulette()
                {
                    Id = rnd.Next(), Status = false
                };
                await RouletteAdapter.SetRoulette(roulette);

                response.StatusCode = HttpStatusCode.OK.GetHashCode();
                response.Data       = roulette;
            }
            catch (Exception ex)
            {
                response.StatusCode = HttpStatusCode.InternalServerError.GetHashCode();
                response.Errors.Add(new Entities.Utils.Error(response.StatusCode.ToString(), ex.Message));
            }
            return(response);
        }
 public async Task SetRoulette(model.Roulette roulette)
 {
     await DistributedCache.SetCacheValueAsync(BaseKey + roulette.Id.ToString(), roulette);
 }