Ejemplo n.º 1
0
        public void CreateBet(int gameId, string userId)
        {
            var ctx = new DAL.BettingRoomEntities();

            DAL.AccountBalance account;

            if (ctx.AccountBalances.Where(a => a.UserId == userId).FirstOrDefault() == null)
            {
                ctx.AccountBalances.Add(new DAL.AccountBalance
                {
                    UserId = userId,
                    AmountInEuro = 100,
                });
                ctx.SaveChanges();

                account = ctx.AccountBalances.Where(a => a.UserId == userId).FirstOrDefault();
            }
            else
            {
                account = ctx.AccountBalances.Where(a => a.UserId == userId).FirstOrDefault();
            }

            var result = Get1X2();
            var game = ctx.Games.Find(gameId);

            var newBet = new DAL.BetOneGame
            {
                GameId = gameId,
                UserId = userId,
                BetAmount = GetBetAmount(),
                C1X2 = result,
                Odds = GetOdds(gameId, result),
                WonOrLose = "NOT FINISH",
            };

            if (newBet.BetAmount <= account.AmountInEuro)
            {
                account.AmountInEuro = account.AmountInEuro - newBet.BetAmount;
                ctx.BetOneGames.Add(newBet);

                ctx.Transactions.Add(new DAL.Transaction()
                {
                    AccountId = account.Id,
                    Amount = newBet.BetAmount,
                    TransactionType = "Bet",
                    TransactionTime = game.GameTime.AddHours(2),
                });
                ctx.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public ActionResult SaveTheBet(Models.BetOneModel model)
        {
            if (ModelState.IsValid)
            {
                var ctx = new DAL.BettingRoomEntities();
                var account = ctx.AccountBalances.Where(a => a.UserId == model.UserId).FirstOrDefault();

                if (account.AmountInEuro >= model.BetAmount)
                {
                    account.AmountInEuro = account.AmountInEuro - model.BetAmount;
                    ctx.SaveChanges();

                    var newBet = new DAL.BetOneGame
                    {
                        GameId = model.GameId,
                        UserId = model.UserId,
                        BetAmount = model.BetAmount,
                        C1X2 = model._1X2,
                        Odds = model.Odds,
                        WonOrLose = "NOT FINISH",
                        BetTime = DateTime.Now,
                    };

                    if (newBet.BetAmount <= account.AmountInEuro)
                    {
                        account.AmountInEuro = account.AmountInEuro - newBet.BetAmount;
                        ctx.BetOneGames.Add(newBet);

                        ctx.Transactions.Add(new DAL.Transaction()
                        {
                            AccountId = account.Id,
                            Amount = newBet.BetAmount,
                            TransactionType = "Bet",
                            TransactionTime = DateTime.Now,
                        });
                        ctx.SaveChanges();
                    }
                    return PartialView("_Success");
                }
                return PartialView("_FinishBet", model);
            }
            return PartialView("_FinishBet", model);
        }