예제 #1
0
        public Roulette Bet(string Id, string UserId, int position, double money)
        {
            if (money > 10000 || money < 1)
            {
                throw new CashOutRangeException();
            }
            Roulette roulette = rouletteRepository.GetById(Id);

            if (roulette == null)
            {
                throw new RouletteNotFound();
            }

            if (roulette.IsOpen == false)
            {
                throw new RouletteClosedException();
            }

            double value = 0d;

            roulette.board[position].TryGetValue(UserId, out value);
            roulette.board[position].Remove(UserId + "");
            roulette.board[position].TryAdd(UserId + "", value + money);

            return(rouletteRepository.Update(roulette.Id, roulette));
        }
        public async Task <ActionResult <Roulette> > Open(Guid rouletteId)
        {
            try
            {
                bool     open            = false;
                Roulette currentRoulette = repository.GetById(rouletteId: rouletteId);
                currentRoulette.Status = "Abierta";
                await Task.Run(() =>
                {
                    open = !repository.OpenRoulette(roulette: currentRoulette);
                });

                if (open)
                {
                    return(Ok(currentRoulette));
                }
                else
                {
                    throw new Exception("No se pudo abrir la ruleta.");
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
예제 #3
0
 public Roulette Find(string Id)
 {
     return(_rouletteRepository.GetById(Id));
 }
예제 #4
0
        private bool IsValidRoulette(Guid idRoulette)
        {
            Roulette roulette = rouletteRepository.GetById(rouletteId: idRoulette);

            return(roulette.Status == "Abierta");
        }