Exemplo n.º 1
0
        public ResponseModel Close(int id, bool state)
        {
            object obj;
            int    status = 404;
            var    result = new BetResponseModel();

            try
            {
                var roulette = rouletteRepo.GetById(id);
                result.Message = ValidateClose(roulette);

                if (result.Message.Count == 0)
                {
                    roulette.State = state;
                    obj            = rouletteRepo.Update(roulette);

                    if (obj != null)
                    {
                        var betList = betRepo.GetByRouleteId(id);

                        foreach (var item in betList)
                        {
                            betResponseModel.Color      = item.Color;
                            betResponseModel.IdRoulette = item.IdRoulette;
                            betResponseModel.Message    = null;
                            betResponseModel.Number     = item.Number;
                            betResponseModelList.Add(betResponseModel);
                        }

                        if (betResponseModelList.Count > 0)
                        {
                            status = 200;
                            obj    = betResponseModelList;
                        }
                        else
                        {
                            obj = "La consulta no produjo ningun resultado.";
                        }
                    }
                    else
                    {
                        obj = "Ha ocurrido un error mientras se actualizaban lso datos.";
                    }
                }
                else
                {
                    obj = result.Message;
                }
            }
            catch (Exception)
            {
                status = 500;
                obj    = "Ha ocurrido un error inesperado, por favor inténtalo nuevamente";
            }

            SetObjectResponse(obj, status);
            return(response);
        }
Exemplo n.º 2
0
 public RouletteBll(ResponseModel response, MessageListModel messageList, List <BetResponseModel> betResponseModelList,
                    BetResponseModel betResponseModel, IRepository <Roulette> rouletteRepo, IRepository <Consumer> consumerRepo, BetRepository betRepo) : base(response, messageList)
 {
     this.betResponseModelList = betResponseModelList;
     this.betResponseModel     = betResponseModel;
     this.rouletteRepo         = rouletteRepo;
     this.consumerRepo         = consumerRepo;
     this.betRepo = betRepo;
 }
Exemplo n.º 3
0
        public BetResponseModel RunRoulette(Bet bet, Consumer user)
        {
            var response = new BetResponseModel();

            try
            {
                var rnd = new Random();
                int colorValue = 2, numberValue = 35;

                var numberResult = rnd.Next(0, 36);
                var result       = MyRoulette.Where(z => z.Value == numberResult).FirstOrDefault();

                if (result != null)
                {
                    response.Number = bet.Number = result.Value;
                    response.Color  = bet.Color = result.Color;

                    var text = "Has ganado!";

                    if (bet.MyBet.ToLower().Equals(response.Color))
                    {
                        user.Money += (bet.Amount * colorValue);
                    }
                    if (bet.MyBet.Equals(response.Number.ToString()))
                    {
                        user.Money += (bet.Amount * numberValue);
                    }

                    if (!bet.MyBet.Equals(response.Number.ToString()) && !bet.MyBet.ToLower().Equals(response.Color))
                    {
                        user.Money -= bet.Amount;
                        text        = "Has perdido!";
                    }

                    response.Message.Add($"{text}, tu saldo actual es : {user.Money}");

                    consumerRepo.Update(user);
                    betRepo.Add(bet);
                }
                else
                {
                    response.Message.Add($"Ha ocurrido un error al realizar la ejecución, inténtalo nuevamente.");
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(response);
        }
Exemplo n.º 4
0
        public IHttpActionResult Post(BetRequestModel requestModel)
        {
            if (ModelState.IsValid)
            {
                PlaceBetCommand placeBetCommand            = Mapper.Map <PlaceBetCommand>(requestModel);
                IEnumerable <ValidationResult> validations = commandDispatcher.Validate(placeBetCommand);

                ModelState.AddModelErrors(validations);

                if (ModelState.IsValid)
                {
                    BetResponseModel responseModel = new BetResponseModel();
                    responseModel.TicketId = commandDispatcher.Dispatch <PlaceBetCommand, string>(placeBetCommand);

                    return(Ok(responseModel));
                }
            }

            return(BadRequest(ModelState));
        }
Exemplo n.º 5
0
        public ResponseModel RunBet(Bet bet, string userid)
        {
            object obj;
            int    status;
            var    result = new BetResponseModel();

            try
            {
                int.TryParse(userid, out int idUser);

                var user     = consumerRepo.GetById(idUser);
                var roulette = rouletteRepo.GetById(bet.IdRoulette);

                result.Message = Validate(bet, roulette, user);

                if (result.Message.Count == 0)
                {
                    GenerateRoulette();
                    obj    = RunRoulette(bet, user);
                    status = 200;
                }
                else
                {
                    status = 404;
                    obj    = result.Message;
                }
            }
            catch (Exception)
            {
                status = 500;
                obj    = "Ha ocurrido un error inesperado, por favor inténtalo nuevamente";
            }

            SetObjectResponse(obj, status);
            return(response);
        }