示例#1
0
        public async Task <ActionResult <Bet> > CreateBet([FromHeader(Name = "IdUser")] string UserId, [FromBody] BetEntity betEntity)
        {
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                try
                {
                    Bet bet = new Bet
                    {
                        IdRoulette = betEntity.IdRoulette,
                        Money      = betEntity.Money,
                        Position   = betEntity.Position,
                        Color      = betEntity.Color
                    };
                    await _betrepository.CreateBet(bet, UserId);

                    return(Ok(bet));
                }
                catch (Exception ex)
                {
                    return(BadRequest(new { error = ex.Message, code = "Error al crear la apuesta" }));
                }
            }
        }
示例#2
0
文件: BetBL.cs 项目: Xerbeth/Ruleta
        public TransactionDTO <MessageDTO> CreateBet(CreateBetDTO createBet)
        {
            TransactionDTO <MessageDTO> transaction = new TransactionDTO <MessageDTO>();

            transaction.Data = new MessageDTO();
            try
            {
                long createRouletteId = _betRepository.CreateBet(createBet);
                if (createRouletteId < 0)
                {
                    transaction.Status  = Common.Status.Failure;
                    transaction.Message = "No fue posible crear la apuesta de juego.";

                    return(transaction);
                }
                transaction.Data.Message = "¡Apuesta aceptada! :)";
                transaction.Data.Flag    = true;
            }
            catch (ArgumentException ex)
            {
                transaction.Status  = Common.Status.Failure;
                transaction.Message = ex.Message;
            }

            return(transaction);
        }
示例#3
0
        public async Task <ActionResult <Bet> > Post([FromBody] Bet newBet)
        {
            try
            {
                bool success = false;
                Request.Headers.TryGetValue("userId", out var userId);
                if (string.IsNullOrEmpty(userId))
                {
                    return(BadRequest(Utils.CreateMessageError(message: "No se encontró {userId} válido en la cabecera.")));
                }
                newBet.Id        = Guid.NewGuid();
                newBet.IdUsuario = userId;
                await Task.Run(() =>
                {
                    success = betRepository.CreateBet(bet: newBet);
                });

                if (!success)
                {
                    return(BadRequest());
                }

                return(Ok(newBet));
            }
            catch (Exception ex)
            { return(BadRequest(ex.Message)); }
        }
示例#4
0
        public void AddBet(User user, Team team, string amountBid)
        {
            Bet bet = new Bet();

            bet.UserName         = user.Username;
            bet.TeamName         = team.TeamName;
            bet.OpposingTeamName = team.OpposingTeamName;
            bet.BettingOdds      = team.BettingOdds;
            bet.isFavourite      = team.isFavourite;
            bet.AmountBid        = decimal.Parse(amountBid);
            bet.BetPayout        = bet.Payout(bet);

            _betRepository.CreateBet(bet);
        }
示例#5
0
        public async Task Addbet(string shortName, string date)
        {
            DateTimeOffset dateDTO;

            if (!DateTimeOffset.TryParse(date, CultureInfo.GetCultureInfo("nb-NO"), DateTimeStyles.None, out dateDTO))
            {
                await ReplyAsync($"Dateformat is incorrect"); return;
            }

            var user = Context.User as SocketGuildUser;

            var bet = new Bet
            {
                Date      = dateDTO,
                ShortName = shortName.ToLower().Trim(),
                AddedBy   = user.Username,
                Created   = DateTimeOffset.Now,
                Locked    = GetLockedDate(dateDTO, DateTimeOffset.Now)
            };

            await _betRepository.CreateBet(bet);

            await ReplyAsync($"{shortName} added");
        }