Exemplo n.º 1
0
        public static void VersionThree(this SeasonBets sBets, AppStatic.Seasons season, AppStatic.BettingSetup bettingSet)
        {
            ListAccess la = new ListAccess();
            List<Game> seasonGames = la.AllSeasonGames((int)season, (int)AppStatic.Leagues.NBA);
            List<Game> teamGames;
            List<Game> bettingSeries = new List<Game>();
            List<Bet> bettingOpps = new List<Bet>();
            bool hasWon = false;
            TimeSpan ts;
            DateTime previousDate = DateTime.MinValue;
            int gameCount = 0;
            foreach (Team team in AppStatic.NBATeams)
            {
                teamGames = seasonGames.Where(sg => sg.AwayTeamId == team.TeamId || sg.HomeTeamId == team.TeamId).OrderBy(sg => sg.GameDate).ToList();
                for (int i = 0; i < teamGames.Count(); i++)
                {
                    while (i < teamGames.Count() && teamGames[i].AwayTeamId == team.TeamId)// && bettingSeries.Count <= 3)
                    {
                        if (teamGames[i].GameId == 105651)
                        {
                            var testOne = true;
                        }
                        if (teamGames[i].GameId == 105651)
                        {
                            var testOne = true;
                        }
                        bettingSeries.Add(teamGames[i]);
                        i++;
                    }

                    if (bettingSeries.Count >= 3)
                    {
                         //i--;
                         Bet bet = new Bet();
                         bet.BetGames = new List<Game>();
                         bet.BetGames.AddRange(bettingSeries);
                         bet.BetADate = bettingSeries[0].GameDate;
                        foreach (Game game in bettingSeries)
                        {
                            if (game.AwayTeamId == game.WinningTeamId)
                            {
                                if (game.AwayTeamSpread < 0)
                                {
                                    int dif = game.HomeTeamScore - game.AwayTeamScore;
                                    if (dif <= game.AwayTeamSpread)
                                    {
                                        hasWon = true;
                                    }
                                }
                                else
                                {
                                    hasWon = true;
                                }
                            }
                            else
                            {
                                if (game.AwayTeamSpread > 0 && (game.HomeTeamScore - game.AwayTeamScore) <= game.AwayTeamSpread && game.WinningTeamId != 0)
                                { hasWon = true;  }
                            }

                            if (hasWon)
                            {
                                int winIndex = bettingSeries.IndexOf(game);
                                switch (winIndex)
                                {
                                    case 0:
                                        bet.WinA = true;
                                        sBets.TotalA++;
                                        break;
                                    case 1:
                                        bet.WinB = true;
                                        bet.BetBDate = game.GameDate;
                                        sBets.TotalB++;
                                        break;
                                    case 2:
                                        bet.WinC = true;
                                        bet.BetBDate = bettingSeries[1].GameDate;
                                        bet.BetCDate = game.GameDate;
                                        sBets.TotalC++;
                                        break;
                                    case 3:
                                        bet.WinD = true;
                                        bet.BetBDate = bettingSeries[1].GameDate;
                                        bet.BetCDate = bettingSeries[2].GameDate;
                                        bet.BetDDate = game.GameDate;
                                        sBets.TotalD++;
                                        break;
                                }
                                break;
                            }
                            else
                            {
                                //bet.Loss = true;
                                //bet.LossDate = game.GameDate;
                            }
                        }
                        if (!hasWon)
                        {
                            bet.Loss = true;
                            bet.LossDate = bettingSeries.Last().GameDate;
                            sBets.TotalGroupLoss++;
                        }
                        sBets.Bets.Add(bet);
                        hasWon = false;
                        bettingSeries.Clear();

                        #region
                        //switch (bettingSet)
                        //{
                        //    //case AppStatic.BettingSetup.MoneyLine:
                        //    //    foreach (Game game in bettingSeries)
                        //    //    {
                        //    //        if (game.AwayTeamId == game.WinningTeamId)
                        //    //        {

                        //    //        }
                        //    //    }

                        //    //    break;
                        //    //case AppStatic.BettingSetup.Spread:
                        //    //    break;
                        //    //case AppStatic.BettingSetup.Spread3Point:
                        //    //    break;

                        //}
                        #endregion

                        #region
                        //if (bettingSeries.Count >= 2)
                        //{
                        //    Bet bet = new Bet();
                        //    bet.WinningBetTeamId = bettingSeries[0].AwayTeamId;
                        //    bet.SeasonId = bettingSeries[0].SeasonId;
                        //    bet.BetStatus = new List<BetStatus>();
                        //    foreach (Game game in bettingSeries)
                        //    {
                        //        switch (bettingSeries.IndexOf(game))
                        //        {
                        //            case 0:
                        //                bet.BetADate = game.GameDate;
                        //                bet.BetAGameId = game.GameId;
                        //                if (game.WinningTeamId == game.AwayTeamId)
                        //                {
                        //                    //bet.WinningBet = "A";
                        //                    bet.BetStatus.Add(new BetStatus { BetStatusTypeId = 1 });
                        //                    // bet.LosingBetTeamId = game.HomeTeamId;
                        //                }
                        //                break;
                        //            case 1:
                        //                bet.BetBDate = game.GameDate;
                        //                bet.BetBGameId = game.GameId;
                        //                if (game.WinningTeamId == game.AwayTeamId)
                        //                {
                        //                    //bet.WinningBet = "B";
                        //                    bet.BetStatus.Add(new BetStatus { BetStatusTypeId = 3 });
                        //                    //bet.LosingBetTeamId = game.HomeTeamId;
                        //                }
                        //                break;
                        //            case 2:
                        //                bet.BetCDate = game.GameDate;
                        //                bet.BetCGameId = game.GameId;
                        //                if (game.WinningTeamId == game.AwayTeamId)
                        //                {
                        //                    //bet.WinningBet = "C";
                        //                    bet.BetStatus.Add(new BetStatus { BetStatusTypeId = 5 });
                        //                    // bet.LosingBetTeamId = game.HomeTeamId;
                        //                }
                        //                break;
                        //            case 3:
                        //                bet.BetDDate = game.GameDate;
                        //                bet.BetDGameId = game.GameId;
                        //                if (game.WinningTeamId == game.AwayTeamId)
                        //                {
                        //                    //bet.WinningBet = "C";
                        //                    bet.BetStatus.Add(new BetStatus { BetStatusTypeId = 7 });
                        //                    // bet.LosingBetTeamId = game.HomeTeamId;
                        //                }
                        //                break;
                        //        }
                        //    }
                        //    if (bet.BetStatus.Count() == 0)
                        //    {
                        //        if (bet.BetCDate.HasPlayed())
                        //        {
                        //            bet.WinningBet = "Loss";
                        //            bet.LosingBetTeamId = bet.WinningBetTeamId;
                        //            bet.BetStatus.Add(new BetStatus { BetStatusTypeId = 26 });
                        //        }
                        //    }

                        //    bet.InsertBet();

                            // gameCount = 0;
                        //}

                        #endregion
                    }
                    else
                    {
                        bettingSeries.Clear();
                    }

                }
                teamGames.Clear();
            }
               sBets.Bets = sBets.Bets.OrderBy(b => b.BetADate).ToList();
               //TODAY'S BETS
               sBets.TodaysBets = sBets.Bets.SelectMany(g => g.BetGames)
               .Where(g => g.GameDate.ToShortDateString() == DateTime.Today.ToShortDateString() && g.GameStatusTypeId==1).ToList();
               sBets.TomorrowBets = sBets.Bets.SelectMany(g => g.BetGames).Where(g => g.GameDate.ToShortDateString() == DateTime.Today.AddDays(1).ToShortDateString() && g.GameStatusTypeId == 1).ToList();

               int bankOne = 800;
               int bankOneWinAmount = 100;
               int bankOneIndex = 1;

               int bankTwo = 800;
               int bankTwoWinAmount = 100;
               int bankTwoIndex = 1;

               int bankThree = 800;
               int bankThreeWinAmount = 100;
               int bankThreeIndex = 1;

               int bankBetIndex = 1;

               int tempA = 0;
               int tempB = 0;
               int tempC = 0;

               foreach(Bet bet in sBets.Bets)
               {
               if (bankBetIndex == 3)
               { bankBetIndex = 1; }
               else
               {  bankBetIndex++; }

               if (!bet.Loss)
               {
                   switch (bankBetIndex)
                   {
                       case 1:
                           bankOne = bankOne + bankOneWinAmount;
                           tempC = (int)(Math.Round(bankOne * .1) / 2);
                           tempB = (int)(Math.Round(tempC * .1) / 2);
                           tempA = (int)(Math.Round(tempB * .1) / 2);

                           break;
                       case 2:
                           bankTwo = bankTwo + bankTwoWinAmount;

                           break;
                       case 3:
                           bankThree = bankThree + bankThreeWinAmount;

                           break;
                   }
               }

            }

            //List<Game> games = la.AllSeasonGames((int)AppStatic.Seasons._2011, (int)AppStatic.Leagues.NBA);
            //int[] teamIds = games.Select(g => g.AwayTeamId);
        }
Exemplo n.º 2
0
        public ActionResult GetGameDates(int seasonId)
        {
            var data = new Object { };
            List<string> gameDatesFormated = new List<string>();
            ListAccess la = new ListAccess();
            List<DateTime> games = la.AllSeasonGames(seasonId, (int)AppStatic.Leagues.NBA).Select(g => g.GameDate).Distinct().ToList();
            foreach (DateTime date in games)
            {
                gameDatesFormated.Add(date.ToString("yyyyMMdd", System.Globalization.CultureInfo.CreateSpecificCulture("en-US")));
            }

            data = new { success = true, dates=gameDatesFormated };

            return Json(data);
        }
Exemplo n.º 3
0
        public ActionResult InsertNBABetting(int seasonId)
        {
            var data = new Object { };

            ListAccess la = new ListAccess();
            List<Game> NBAGames = la.AllSeasonGames(seasonId, 2);

            List<Team> teams = AppStatic.NBATeams;
            List<Game> gameList = new List<Game>();
            List<Game> bettingSeries = new List<Game>();
            List<Bet> bettingOpps = new List<Bet>();

            TimeSpan ts;
            DateTime previousDate = DateTime.MinValue;

            int gameCount = 0;

            foreach (Team team in teams)
            {
                gameList = NBAGames.Where(g => g.AwayTeamId == team.TeamId && g.AwayTeamConferenceId != g.HomeTeamConferenceId).OrderBy(g => g.GameDate).ToList();

                for (int i = 0; i < gameList.Count(); i++)
                {
                    if (i != 0)
                    {
                        previousDate = gameList[i-1].GameDate;
                        ts = gameList[i].GameDate - previousDate;
                        if (ts.Days <= 3)
                        {
                            gameCount++;
                            if (gameCount >= 2)
                            {
                                if (i - 2 >= 0)
                                {
                                    bettingSeries.Add(gameList[i - 2]);
                                }
                                bettingSeries.Add(gameList[i-1]);
                                bettingSeries.Add(gameList[i]);

                                Bet bet = new Bet();
                                bet.WinningBetTeamId = bettingSeries[0].AwayTeamId;
                                bet.SeasonId = bettingSeries[0].SeasonId;
                                bet.BetStatus = new List<BetStatus>();
                                foreach (Game game in bettingSeries)
                                {
                                    switch (bettingSeries.IndexOf(game))
                                    {
                                        case 0:
                                            bet.BetADate = game.GameDate;
                                            bet.BetAGameId = game.GameId;
                                            if (game.WinningTeamId == game.AwayTeamId)
                                            {
                                                bet.WinningBet = "A";
                                                bet.BetStatus.Add(new BetStatus { BetStatusTypeId=1 });
                                                bet.LosingBetTeamId = game.HomeTeamId;
                                            }
                                            break;
                                        case 1:
                                            bet.BetBDate = game.GameDate;
                                            bet.BetBGameId = game.GameId;
                                            if (game.WinningTeamId == game.AwayTeamId)
                                            {
                                                bet.WinningBet = "B";
                                                bet.BetStatus.Add(new BetStatus { BetStatusTypeId = 3 });
                                                bet.LosingBetTeamId = game.HomeTeamId;
                                            }
                                            break;
                                        case 2:
                                            bet.BetCDate = game.GameDate;
                                            bet.BetCGameId = game.GameId;
                                            if (game.WinningTeamId == game.AwayTeamId)
                                            {
                                                bet.WinningBet = "C";
                                                bet.BetStatus.Add(new BetStatus { BetStatusTypeId = 5 });
                                                bet.LosingBetTeamId = game.HomeTeamId;
                                            }
                                            break;
                                    }
                                }
                                if (bet.BetStatus.Count() == 0)
                                {
                                    if (bet.BetCDate.HasPlayed())
                                    {
                                        bet.WinningBet = "Loss";
                                        bet.LosingBetTeamId = bet.WinningBetTeamId;
                                        bet.BetStatus.Add(new BetStatus { BetStatusTypeId = 26 });
                                    }
                                }

                                bet.InsertBet();

                                gameCount = 0;
                                bettingSeries.Clear();
                                //bet.BetADate = bettingSeries[0].GameDate;
                                //bet.BetBDate = bettingSeries[1].GameDate;
                                //if (bettingSeries.Count() > 2)
                                //{
                                //    bet.BetCDate = bettingSeries[2].GameDate;
                                //}

                            }
                        }
                        else
                        {
                            gameCount = 0;
                            bettingSeries.Clear();
                        }
                    }
                }

                gameList.Clear();
            }

            data = new { success = true };

            return Json(data);
        }
Exemplo n.º 4
0
        public ActionResult CreateNBABetting(int seasonId)
        {
            var data = new Object { };

            ListAccess la = new ListAccess();
            List<Game> NBAGames = la.AllSeasonGames(seasonId, 2);

            List<Team> teams = AppStatic.NBATeams;
            List<Game> gameList = new List<Game>();
            List<Game> bettingSeries = new List<Game>();
            List<Bet> bettingOpps = new List<Bet>();

            TimeSpan ts;
            DateTime previousDate = DateTime.MinValue;

            int gameCount = 0;

            foreach (Team team in teams)
            {
                gameList = NBAGames.Where(g => g.AwayTeamId == team.TeamId && g.AwayTeamConferenceId != g.HomeTeamConferenceId).OrderBy(g => g.GameDate).ToList();
                for (int i = 0; i < gameList.Count(); i++)
                {
                    if (i != 0)
                    {
                        previousDate = gameList[i - 1].GameDate;
                        ts = gameList[i].GameDate - previousDate;
                        gameCount = i;
                        try
                        {
                            while (ts.Days <= 3)
                            {
                                bettingSeries.Add(gameList[gameCount - 1]);
                                ts = gameList[gameCount].GameDate - bettingSeries.Last().GameDate;
                                gameCount++;
                                //if (gameCount > gameList.Count)
                                //{ break;  }
                            }
                        }
                        catch (Exception ex)
                        {
                            //probably index out of range error
                        }
                        if (gameCount > i)
                        { i = gameCount - 1; }

                        #region
                        if (bettingSeries.Count >= 2)
                        {
                            Bet bet = new Bet();
                            bet.WinningBetTeamId = bettingSeries[0].AwayTeamId;
                            bet.SeasonId = bettingSeries[0].SeasonId;
                            bet.BetStatus = new List<BetStatus>();
                            foreach (Game game in bettingSeries)
                            {
                                switch (bettingSeries.IndexOf(game))
                                {
                                    case 0:
                                        bet.BetADate = game.GameDate;
                                        bet.BetAGameId = game.GameId;
                                        if (game.WinningTeamId == game.AwayTeamId)
                                        {
                                            //bet.WinningBet = "A";
                                            bet.BetStatus.Add(new BetStatus { BetStatusTypeId = 1 });
                                            // bet.LosingBetTeamId = game.HomeTeamId;
                                        }
                                        break;
                                    case 1:
                                        bet.BetBDate = game.GameDate;
                                        bet.BetBGameId = game.GameId;
                                        if (game.WinningTeamId == game.AwayTeamId)
                                        {
                                            //bet.WinningBet = "B";
                                            bet.BetStatus.Add(new BetStatus { BetStatusTypeId = 3 });
                                            //bet.LosingBetTeamId = game.HomeTeamId;
                                        }
                                        break;
                                    case 2:
                                        bet.BetCDate = game.GameDate;
                                        bet.BetCGameId = game.GameId;
                                        if (game.WinningTeamId == game.AwayTeamId)
                                        {
                                            //bet.WinningBet = "C";
                                            bet.BetStatus.Add(new BetStatus { BetStatusTypeId = 5 });
                                            // bet.LosingBetTeamId = game.HomeTeamId;
                                        }
                                        break;
                                    case 3:
                                        bet.BetDDate = game.GameDate;
                                        bet.BetDGameId = game.GameId;
                                        if (game.WinningTeamId == game.AwayTeamId)
                                        {
                                            //bet.WinningBet = "C";
                                            bet.BetStatus.Add(new BetStatus { BetStatusTypeId = 7 });
                                            // bet.LosingBetTeamId = game.HomeTeamId;
                                        }
                                        break;
                                }
                            }
                            if (bet.BetStatus.Count() == 0)
                            {
                                if (bet.BetCDate.HasPlayed())
                                {
                                    bet.WinningBet = "Loss";
                                    bet.LosingBetTeamId = bet.WinningBetTeamId;
                                    bet.BetStatus.Add(new BetStatus { BetStatusTypeId = 26 });
                                }
                            }

                            bet.InsertBet();

                           // gameCount = 0;
                        }

                        #endregion

                        bettingSeries.Clear();
                    }
                }
                gameList.Clear();
            }

            //foreach (Team team in teams)
            //{
            //    gameList = NBAGames.Where(g => g.AwayTeamId == team.TeamId && g.AwayTeamConferenceId != g.HomeTeamConferenceId).OrderBy(g => g.GameDate).ToList();

            //    for (int i = 0; i < gameList.Count(); i++)
            //    {
            //        if (i != 0)
            //        {
            //            previousDate = gameList[i - 1].GameDate;
            //            ts = gameList[i].GameDate - previousDate;
            //            if (ts.Days <= 3)
            //            {
            //                gameCount++;
            //                if (gameCount >= 2)
            //                {
            //                    if (i - 2 >= 0)
            //                    {
            //                        bettingSeries.Add(gameList[i - 2]);
            //                    }
            //                    bettingSeries.Add(gameList[i - 1]);
            //                    bettingSeries.Add(gameList[i]);

            //                    Bet bet = new Bet();
            //                    bet.WinningBetTeamId = bettingSeries[0].AwayTeamId;
            //                    bet.SeasonId = bettingSeries[0].SeasonId;
            //                    bet.BetStatus = new List<BetStatus>();
            //                    foreach (Game game in bettingSeries)
            //                    {
            //                        switch (bettingSeries.IndexOf(game))
            //                        {
            //                            case 0:
            //                                bet.BetADate = game.GameDate;
            //                                bet.BetAGameId = game.GameId;
            //                                if (game.WinningTeamId == game.AwayTeamId)
            //                                {
            //                                    //bet.WinningBet = "A";
            //                                    bet.BetStatus.Add(new BetStatus { BetStatusTypeId = 1 });
            //                                   // bet.LosingBetTeamId = game.HomeTeamId;
            //                                }
            //                                break;
            //                            case 1:
            //                                bet.BetBDate = game.GameDate;
            //                                bet.BetBGameId = game.GameId;
            //                                if (game.WinningTeamId == game.AwayTeamId)
            //                                {
            //                                    //bet.WinningBet = "B";
            //                                    bet.BetStatus.Add(new BetStatus { BetStatusTypeId = 3 });
            //                                    //bet.LosingBetTeamId = game.HomeTeamId;
            //                                }
            //                                break;
            //                            case 2:
            //                                bet.BetCDate = game.GameDate;
            //                                bet.BetCGameId = game.GameId;
            //                                if (game.WinningTeamId == game.AwayTeamId)
            //                                {
            //                                    //bet.WinningBet = "C";
            //                                    bet.BetStatus.Add(new BetStatus { BetStatusTypeId = 5 });
            //                                   // bet.LosingBetTeamId = game.HomeTeamId;
            //                                }
            //                                break;
            //                        }
            //                    }
            //                    if (bet.BetStatus.Count() == 0)
            //                    {
            //                        if (bet.BetCDate.HasPlayed())
            //                        {
            //                            bet.WinningBet = "Loss";
            //                            bet.LosingBetTeamId = bet.WinningBetTeamId;
            //                            bet.BetStatus.Add(new BetStatus { BetStatusTypeId = 26 });
            //                        }
            //                    }

            //                    bet.InsertBet();

            //                    gameCount = 0;
            //                    bettingSeries.Clear();
            //                    //bet.BetADate = bettingSeries[0].GameDate;
            //                    //bet.BetBDate = bettingSeries[1].GameDate;
            //                    //if (bettingSeries.Count() > 2)
            //                    //{
            //                    //    bet.BetCDate = bettingSeries[2].GameDate;
            //                    //}

            //                }
            //            }
            //            else
            //            {
            //                gameCount = 0;
            //                bettingSeries.Clear();
            //            }
            //        }
            //    }

            //    gameList.Clear();
            //}

            data = new { success = true };

            return Json(data);
        }