Ejemplo n.º 1
0
        public override Empty UpdateMortgage(BetInput input)
        {
            Assert(Context.Sender == State.ContractManager.Value, "Only manager can perform this action.");
            Assert(input.Int64Value > 0, "Update mortgage value should be more than 0.");

            State.MortgageBalance.Value += input.Int64Value;

            return(new Empty());
        }
Ejemplo n.º 2
0
        public override Empty UserPlayBet(BetInput input)
        {
            Assert(input.Int64Value >= State.MinBet.Value && input.Int64Value <= State.MaxBet.Value, $"Input balance not in boundary({State.MinBet.Value}, {State.MaxBet.Value}).");
            //Assert(input.Int64Value > State.WinerHistory[Context.Sender], "Should bet bigger than your reward money.");
            State.TotalBetBalance.Value = State.TotalBetBalance.Value.Add(input.Int64Value);

            var result = WinOrLose(input.Int64Value);

            if (result == 0)
            {
                State.LoserHistory[Context.Sender] = State.LoserHistory[Context.Sender].Add(input.Int64Value);
            }
            else
            {
                State.RewardBalance.Value           = State.RewardBalance.Value.Add(result);
                State.WinnerHistory[Context.Sender] = State.WinnerHistory[Context.Sender].Add(result);
            }

            return(new Empty());
        }
        public IActionResult Bet([FromHeader(Name = "user-id")] string UserId, [FromRoute(Name = "id")] string id,
                                 [FromBody] BetInput request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new
                {
                    error = true,
                    msg = "Bad Request"
                }));
            }

            try
            {
                Roulette roulette = rouletteService.Bet(id, UserId, request.position, request.money);
                return(Ok(roulette));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(StatusCode(405));
            }
        }
Ejemplo n.º 4
0
        public override Empty UserPlayBet(BetInput input)
        {
            Assert(input.Int64Value >= State.MinBet.Value && input.Int64Value <= State.MaxBet.Value,
                   $"Input balance not in boundary({State.MinBet.Value}, {State.MaxBet.Value}).");
            //Assert(input.Int64Value > State.WinerHistory[Context.Sender]);

            var result = WinOrLose(input.Int64Value);

            State.LoserHistory[Context.Sender] += input.Int64Value;

            if (result == 0)
            {
                State.TotalBetBalance.Value        += input.Int64Value;
                State.LoserHistory[Context.Sender] += result;
            }
            else
            {
                State.RewardBalance.Value          += result;
                State.WinerHistory[Context.Sender] += result;
            }

            return(new Empty());
        }
Ejemplo n.º 5
0
 public async Task <OperationResult> BetAsync(string rouletteCode, string userId, BetInput body)
 {
     return(await _instanceServices.First(x => x.ScaleUpStrategy == _rouletteSettings.ScaleUpStrategy).BetAsync(rouletteCode, userId, body));
 }
Ejemplo n.º 6
0
        public async Task <OperationResult> BetAsync(string rouletteCode, string userId, BetInput bet)
        {
            var result          = new OperationResult();
            var rouletteStorage = _rouletteRepositories.First(x => x.StorageProvider == _rouletteSettings.StorageProvider);
            var roulette        = await rouletteStorage.FindByCodeAsync(rouletteCode);

            if (roulette != null)
            {
                if (roulette.RouletteStatus != RouletteStatus.Open)
                {
                    throw new RouletteException("La ruleta se encuentra cerrada");
                }
                var betStorage = _betRepositories.First(x => x.StorageProvider == _rouletteSettings.StorageProvider);
                var betToSave  = new Bet
                {
                    AmountToBet  = bet.BetAmount,
                    RouletteCode = rouletteCode,
                    UserId       = userId,
                    Number       = bet.Number.ToString(),
                    Color        = bet.Number % 2 == 0 ? Color.Red.ToString() : Color.Black.ToString()
                };
                await betStorage.CreateAsync(betToSave);
            }
            else
            {
                throw new RouletteException("No se encontró una ruleta abierta con ese código");
            }
            return(result);
        }
 public Task <OperationResult> BetAsync(string rouletteCode, string userId, BetInput body)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 8
0
 public async Task <IActionResult> BetRoulettaAsync(string rouletteCode, BetInput input, [FromHeader(Name = "User-Id")] string userId)
 {
     return(Ok(await _rouletteService.BetAsync(rouletteCode, userId, input)));
 }
Ejemplo n.º 9
0
 public IHttpActionResult Post([FromBody] BetInput betInput)
 {
     return(Ok <BetInput>(betInput));
 }