Exemplo n.º 1
0
        public async Task <IActionResult> Create(BetInputModel model)
        {
            var currentBet = this.betRepository
                             .All()
                             .FirstOrDefault(x => x.Id == model.Id);

            currentBet.IsCurrentBet = false;
            currentBet.BetAmount    = model.BetAmount;
            currentBet.AmountOfWin  = currentBet.Odds.Sum(x => x.OddValue) * currentBet.BetAmount;
            currentBet.Date         = DateTime.UtcNow;
            currentBet.User.Points -= model.BetAmount;


            await this.betRepository.SaveChangesAsync();

            var nextCurrentBet = this.betService.GetCurrentBet(currentBet.User.UserName);


            var homeModel = new HomePageViewModel
            {
                Matches = this.homeService.Matches(),
                MyBet   = nextCurrentBet
            };

            return(this.RedirectToAction("Index", "Home", homeModel));
        }
        public ActionResult Bet(BetInputModel model)
        {
            if (model != null && this.ModelState.IsValid)
            {
                var bet = Mapper.Map<Bet>(model);
                bet.UserId = this.User.Identity.GetUserId();
                this.Data.Bets.Add(bet);
                this.Data.SaveChanges();

                var bets = this.Data.Bets
                    .All()
                    .Where(x => x.MatchId == bet.MatchId && x.TeamId == bet.TeamId)
                    .Sum(x => x.Ammount);

                return this.Content(bets.ToString());
            }

            return this.Json("Error");
        }
Exemplo n.º 3
0
        public ActionResult Bet(BetInputModel model)
        {
            if (model.HomeBet != 0 && model.AwayBet == 0)
            {
                var homeBetToDb = Mapper.Map<Bet>(model);
                homeBetToDb.AwayBet = 0;
                homeBetToDb.UserId = this.User.Identity.GetUserId();

                this.Data.Bets.Add(homeBetToDb);
                this.Data.SaveChanges();

                var homeBetFromDb = this.Data.Bets
                    .All()
                    .Where(x => x.MatchId == model.MatchId)
                    .Sum(x => x.HomeBet);

                return this.Content(homeBetFromDb.ToString());
            }

            if (model.HomeBet == 0 && model.AwayBet != 0)
            {
                var awayBetToDb = Mapper.Map<Bet>(model);
                awayBetToDb.HomeBet = 0;
                awayBetToDb.UserId = this.User.Identity.GetUserId();

                this.Data.Bets.Add(awayBetToDb);
                this.Data.SaveChanges();

                var awayBetFromDb = this.Data.Bets
                    .All()
                    .Where(x => x.MatchId == model.MatchId)
                    .Sum(x => x.AwayBet);

                return this.Content(awayBetFromDb.ToString());
            }

            return this.Json(this.ModelState, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 4
0
        public ActionResult Bet(BetInputModel model)
        {
            if (model.HomeBet != 0 && model.AwayBet == 0)
            {
                var homeBetToDb = Mapper.Map <Bet>(model);
                homeBetToDb.AwayBet = 0;
                homeBetToDb.UserId  = this.User.Identity.GetUserId();

                this.Data.Bets.Add(homeBetToDb);
                this.Data.SaveChanges();

                var homeBetFromDb = this.Data.Bets
                                    .All()
                                    .Where(x => x.MatchId == model.MatchId)
                                    .Sum(x => x.HomeBet);

                return(this.Content(homeBetFromDb.ToString()));
            }

            if (model.HomeBet == 0 && model.AwayBet != 0)
            {
                var awayBetToDb = Mapper.Map <Bet>(model);
                awayBetToDb.HomeBet = 0;
                awayBetToDb.UserId  = this.User.Identity.GetUserId();

                this.Data.Bets.Add(awayBetToDb);
                this.Data.SaveChanges();

                var awayBetFromDb = this.Data.Bets
                                    .All()
                                    .Where(x => x.MatchId == model.MatchId)
                                    .Sum(x => x.AwayBet);

                return(this.Content(awayBetFromDb.ToString()));
            }

            return(this.Json(this.ModelState, JsonRequestBehavior.AllowGet));
        }
        public ActionResult AddBet(SportSystem.Models.Match match, int teamId, BetInputModel betInput)
        {
            if (match == null)
            {
                return this.HttpNotFound();
            }

            if (match.HomeTeamId != teamId && match.AwayTeamId != teamId)
            {
                return this.HttpNotFound();
            }

            var bet = Mapper.Map<Bet>(betInput);
            bet.UserId = this.UserProfille.Id;
            bet.TeamId = teamId;
            bet.MatchId = match.Id;
            this.Data.Bets.Add(bet);

            this.Data.SaveChanges();

            var newAmmount = this.Data.Bets.All().Where(b => b.TeamId == teamId && b.MatchId == match.Id).Sum(b => b.Ammount);

            return this.Content(newAmmount.ToString(CultureInfo.InvariantCulture));
        }