示例#1
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);
        }
示例#2
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);
        }