public IResponse Create()
        {
            IResponse response;

            try
            {
                var roulette = new ExportModels.Roulette
                {
                    id     = Guid.NewGuid(),
                    status = ExportModels.Roulette.Status.create
                };
                _client.Set(roulette.id.ToString(), roulette.ToJson());
                response = new ExportModels.Response
                {
                    Status  = ExportModels.Response.ResponseStatus.ok,
                    Content = new ResumeResponseContent
                    {
                        Content = roulette.id.ToString()
                    }
                };
            }
            catch (Exception e)
            {
                response = new ExportModels.Response
                {
                    Status  = ExportModels.Response.ResponseStatus.fail,
                    Content = new ResumeResponseContent
                    {
                        Content = e.ToJson()
                    }
                };
            }
            return(response);
        }
        private bool ValidateBet(ExportModels.Roulette roulette, Bet bet, out Response response)
        {
            if (!roulette.status.Equals(ExportModels.Roulette.Status.open))
            {
                response = new Response
                {
                    Status  = Response.ResponseStatus.fail,
                    Content = new ResumeResponseContent {
                        Content = string.Format("Ruleta {0} no esta en un estado valido para aceptar una apuesta.", roulette.id.ToString())
                    }
                };
                return(false);
            }

            if (!(bet.Amount > 0 && bet.Amount <= 10000))
            {
                response = new Response
                {
                    Status  = Response.ResponseStatus.fail,
                    Content = new ResumeResponseContent {
                        Content = "El monto de la apuesta debe estar comprendido entre 1 y 10000 dollares."
                    }
                };
                return(false);
            }

            if (roulette.bets != null)
            {
                if (roulette.bets.Where(b => b.ClientId.Equals(bet.ClientId)).Any())
                {
                    response = new Response
                    {
                        Status  = Response.ResponseStatus.fail,
                        Content = new ResumeResponseContent {
                            Content = string.Format("El cliente {0} tiene ya una apuesta en la Ruleta {1}.", bet.ClientId, roulette.id.ToString())
                        }
                    };
                    return(false);
                }
                if (bet.Type.Equals(Bet.BetType.num) && roulette.bets.Where(b => b.Num.Equals(bet.Num)).Any())
                {
                    response = new Response
                    {
                        Status  = Response.ResponseStatus.fail,
                        Content = new ResumeResponseContent {
                            Content = string.Format("El nĂºmero fue ya seleccionado para la ruleta El monto de la apuesta debe estar comprendido entre 1 y 10000 dollares.", roulette.id.ToString())
                        }
                    };
                    return(false);
                }
            }
            response = new Response();
            return(true);
        }
 private bool ValidateRouletteClose(ExportModels.Roulette roulette, out Response response)
 {
     if (roulette.status == ExportModels.Roulette.Status.close)
     {
         response = new Response
         {
             Status  = Response.ResponseStatus.fail,
             Content = new ResumeResponseContent {
                 Content = string.Format("Ruleta {0} en estado no valido", roulette.id)
             }
         };
         return(false);
     }
     response = new Response();
     return(true);
 }
        private void SelectWinner(ExportModels.Roulette roulette, out int winnerValue)
        {
            var random = new Random();

            winnerValue = random.Next(0, 38);
            foreach (var bet in roulette.bets)
            {
                if (bet.Type.Equals(Bet.BetType.num) && bet.Num.Equals(winnerValue))
                {
                    bet.Amount *= 5;
                }
                else if (bet.Type.Equals(Bet.BetType.color) && (
                             (winnerValue.IsEwen() && bet.Color.Equals(Bet.BetColor.red)) ||
                             (!winnerValue.IsEwen() && bet.Color.Equals(Bet.BetColor.black))))
                {
                    bet.Amount *= 1.8;
                }
                else
                {
                    bet.Amount *= -1;
                }
            }
        }