Ejemplo n.º 1
0
        public Bet CheckGameBet(int gameId)
        {
            Bet bet = new Bet();
            string queryString = "SELECT Bet.[BetId],[BetADate],[BetBDate],[BetCDate],[BetDDate],[WinningBet],[WinningBetTeamId]" +
                                        ",[LosingBetTeamId],[BetNote] FROM [dbo].[Bet] INNER JOIN BetGame ON Bet.BetId = BetGame.BetId WHERE BetGame.GameId = " + gameId;

            using (SqlConnection connection = new SqlConnection(Base.conn))
            {
                // Create the Command and Parameter objects.
                SqlCommand command = new SqlCommand(queryString, connection);
                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        bet.BetId = reader.GetInt32(0);
                        bet.BetADate = reader.GetDateSafe(1);
                        bet.BetBDate = reader.GetDateSafe(2);
                        bet.BetCDate = reader.GetDateSafe(3);
                        bet.BetDDate = reader.GetDateSafe(4);
                        bet.WinningBet = reader.GetString(5);
                        bet.WinningBetTeamId = reader.GetInt32(6);
                        bet.LosingBetTeamId = reader.GetInt32(7);
                        bet.BetNote = reader.GetStringSafe(8);
                    }
                    reader.Close();
                }
                catch (Exception ex)
                {
                    throw (ex);
                }

            }

            return bet;
        }
Ejemplo n.º 2
0
        public List<Bet> NBABets(int seasonId)
        {
            List<Bet> bets = new List<Bet>();
            string queryString = "SELECT * FROM [dbo].[NBABets]";
            using (SqlConnection connection = new SqlConnection(Base.conn))
            {
                // Create the Command and Parameter objects.
                SqlCommand command = new SqlCommand(queryString, connection);
                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        if (reader.GetInt32(3) == seasonId)
                        {
                            Bet bet = new Bet();
                            bet.BetId = reader.GetInt32(0);
                            bet.BetStatusText = reader.GetString(1);
                            bet.BetNote = reader.GetString(2);
                            bet.SeasonId = reader.GetInt32(3);
                            bet.BetAGameId = reader.GetInt32(4);
                            bet.BetBGameId = reader.GetInt32(5);
                            bet.BetCGameId = reader.GetInt32(6);
                            bet.BetDGameId = reader.GetInt32(60);
                            bet.BetADate = reader.GetDateSafe(7);

                            bet.BetGames = new List<Game>();

                            if (bet.BetAGameId != 0)
                            {
                                bet.BetGames.Add(new Game
                                {
                                    GameId = bet.BetAGameId,
                                    GameDate = reader.GetDateSafe(8),
                                    HomeTeamName = reader.GetString(9),
                                    HomeTeamScore = reader.GetInt32(10),
                                    AwayTeamName = reader.GetString(11),
                                    AwayTeamScore = reader.GetInt32(12),
                                    WinningTeamName = reader.GetString(13),
                                    HomeTeamMoneyLine = reader.GetInt32(14),
                                    HomeTeamSpread = reader.GetDecimalSafe(15),
                                    AwayTeamMoneyLine = reader.GetInt32(16),
                                    AwayTeamSpread = reader.GetDecimalSafe(17),
                                    WinningTeamId = reader.GetInt32(18),
                                    HomeTeamId = reader.GetInt32(19),
                                    AwayTeamId = reader.GetInt32(20),
                                    WonSpread = reader.GetBoolean(61),
                                    WonMoneyLine = reader.GetBoolean(62)
                                });
                                if (bet.BetGames.Last().WinningTeamId == bet.BetGames.Last().AwayTeamId)
                                {
                                    bet.WinA = true;
                                }
                                if (bet.BetGames.Last().WonSpread)
                                {
                                    bet.WinA = true;
                                }
                                if (!bet.BetGames.Last().WonSpread && !bet.BetGames.Last().WonMoneyLine)
                                {
                                    bet.WinA = false;
                                }
                            }

                            if (bet.BetBGameId != 0)
                            {
                                bet.BetGames.Add(new Game
                                {
                                    GameId = bet.BetBGameId,
                                    GameDate = reader.GetDateSafe(21),
                                    HomeTeamName = reader.GetString(22),
                                    HomeTeamScore = reader.GetInt32(23),
                                    AwayTeamName = reader.GetString(24),
                                    AwayTeamScore = reader.GetInt32(25),
                                    WinningTeamName = reader.GetString(26),
                                    HomeTeamMoneyLine = reader.GetInt32(27),
                                    HomeTeamSpread = reader.GetDecimalSafe(28),
                                    AwayTeamMoneyLine = reader.GetInt32(29),
                                    AwayTeamSpread = reader.GetDecimalSafe(30),
                                    WinningTeamId = reader.GetInt32(31),
                                    HomeTeamId = reader.GetInt32(32),
                                    AwayTeamId = reader.GetInt32(33),
                                    WonSpread = reader.GetBoolean(63),
                                    WonMoneyLine = reader.GetBoolean(64)
                                });
                                if (bet.BetGames.Last().WinningTeamId == bet.BetGames.Last().AwayTeamId)
                                {
                                    bet.WinB = true;
                                }
                                if (bet.BetGames.Last().WonSpread)
                                {
                                    bet.WinB = true;
                                }
                                if (!bet.BetGames.Last().WonSpread && !bet.BetGames.Last().WonMoneyLine)
                                {
                                    bet.WinB = false;
                                }
                            }

                            if (bet.BetCGameId != 0)
                            {
                                bet.BetGames.Add(new Game
                                {
                                    GameId = bet.BetCGameId,
                                    GameDate = reader.GetDateSafe(34),
                                    HomeTeamName = reader.GetString(35),
                                    HomeTeamScore = reader.GetInt32(36),
                                    AwayTeamName = reader.GetString(37),
                                    AwayTeamScore = reader.GetInt32(38),
                                    WinningTeamName = reader.GetString(39),
                                    HomeTeamMoneyLine = reader.GetInt32(40),
                                    HomeTeamSpread = reader.GetDecimalSafe(41),
                                    AwayTeamMoneyLine = reader.GetInt32(42),
                                    AwayTeamSpread = reader.GetDecimalSafe(43),
                                    WinningTeamId = reader.GetInt32(44),
                                    HomeTeamId = reader.GetInt32(45),
                                    AwayTeamId = reader.GetInt32(46),
                                    WonSpread = reader.GetBoolean(65),
                                    WonMoneyLine = reader.GetBoolean(66)
                                });
                                if (bet.BetGames.Last().WinningTeamId == bet.BetGames.Last().AwayTeamId)
                                {
                                    bet.WinC = true;
                                }
                                if (bet.BetGames.Last().WonSpread)
                                {
                                    bet.WinC = true;
                                }
                                if (!bet.BetGames.Last().WonSpread && !bet.BetGames.Last().WonMoneyLine)
                                {
                                    bet.WinC = false;
                                }
                            }

                            if (bet.BetDGameId != 0)
                            {
                                bet.BetGames.Add(new Game
                                {
                                    GameId = bet.BetDGameId,
                                    GameDate = reader.GetDateSafe(47),
                                    HomeTeamName = reader.GetString(48),
                                    HomeTeamScore = reader.GetInt32(49),
                                    AwayTeamName = reader.GetString(50),
                                    AwayTeamScore = reader.GetInt32(51),
                                    WinningTeamName = reader.GetString(52),
                                    HomeTeamMoneyLine = reader.GetInt32(53),
                                    HomeTeamSpread = reader.GetDecimalSafe(54),
                                    AwayTeamMoneyLine = reader.GetInt32(55),
                                    AwayTeamSpread = reader.GetDecimalSafe(56),
                                    WinningTeamId = reader.GetInt32(57),
                                    HomeTeamId = reader.GetInt32(58),
                                    AwayTeamId = reader.GetInt32(59),
                                    WonSpread = reader.GetBoolean(67),
                                    WonMoneyLine = reader.GetBoolean(68)
                                });
                                if (bet.BetGames.Last().WinningTeamId == bet.BetGames.Last().AwayTeamId)
                                {
                                    bet.WinD = true;
                                }
                                if (bet.BetGames.Last().WonSpread)
                                {
                                    bet.WinD = true;
                                }
                                if (!bet.BetGames.Last().WonSpread && !bet.BetGames.Last().WonMoneyLine)
                                {
                                    bet.WinD = false;
                                }
                            }

                            bets.Add(bet);
                        }
                    }
                    reader.Close();
                }
                catch (Exception ex)
                {
                    SportsError sError = new SportsError(ex);
                }
            }

            return bets.OrderBy(b => b.BetADate).ToList();
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public bool UpdateGame()
        {
            if (this.GameId != 0)
            {
                string queryString = "UPDATE [dbo].[Game] "
                                     + "SET [GameStatusTypeId] = @GameStatusTypeId "
                                     + " ,[HomeTeamScore] = @HomeTeamScore"
                                     + " ,[AwayTeamScore] = @AwayTeamScore"
                                     + " ,[WinningTeamId] = @WinningTeamId"
                                     + " WHERE GameId = @GameId";

                using (SqlConnection connection = new SqlConnection(Base.conn))
                {
                    // Create the Command and Parameter objects.
                    SqlCommand command = new SqlCommand(queryString, connection);
                    command.Parameters.AddWithValue("@GameId", this.GameId);
                    //command.Parameters.AddWithValue("@GameDate", this.GameDate);
                    command.Parameters.AddWithValue("@GameStatusTypeId", this.GameStatusTypeId);
                    command.Parameters.AddWithValue("@HomeTeamScore", this.HomeTeamScore);
                    command.Parameters.AddWithValue("@AwayTeamScore", this.AwayTeamScore);
                    command.Parameters.AddWithValue("@WinningTeamId", this.WinningTeamId);

                    try
                    {
                        connection.Open();
                        command.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        SportsError sError = new SportsError(ex, this.GameId);
                    }
                }


                Utiliy u   = new Utiliy();
                Bet    bet = u.CheckGameBet(this.GameId);
                if (bet.BetId != 0)
                {
                    //This is a own bet
                    if (bet.WinningBetTeamId == this.WinningTeamId)
                    {
                        if (this.GameDate == bet.BetADate)
                        {
                            bet.WinningBet = "A";
                        }
                        if (this.GameDate == bet.BetBDate)
                        {
                            bet.WinningBet = "B";
                        }
                        if (this.GameDate == bet.BetCDate)
                        {
                            bet.WinningBet = "C";
                        }
                        if (this.GameDate == bet.BetDDate)
                        {
                            bet.WinningBet = "D";
                        }

                        bet.TempUpdateBet();
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public bool TempUpdateBet()
        {
            Bet betCheck = new Bet();

            if (betCheck.BetId != 0)
            {
                this.BetId = betCheck.BetId;
            }
            string queryString = "";

            queryString = "UPDATE [dbo].[Bet]"
                                + "  SET [WinningBet] = @WinningBet"
                                    + " ,[BetNote] = @BetNote"
                               + " WHERE BetId = " + this.BetId.ToString()
                               + " SET @betId = " + this.BetId.ToString();

            using (SqlConnection connection = new SqlConnection(Base.conn))
            {
                if (String.IsNullOrEmpty(this.BetNote)) { this.BetNote = ""; }
                // Create the Command and Parameter objects.
                SqlCommand command = new SqlCommand(queryString, connection);
                command.Parameters.AddWithValue("@WinningBet", this.WinningBet);
                command.Parameters.AddWithValue("@BetNote", this.BetNote);
                command.Parameters.Add("@betId", SqlDbType.Int, 0, "betId");
                command.Parameters["@betId"].Direction = ParameterDirection.Output;
                try
                {
                    connection.Open();
                    command.ExecuteNonQuery();
                    this.BetId = (int)command.Parameters["@betId"].Value;
                }
                catch (Exception ex)
                {
                    SportsError sError = new SportsError(ex, this.BetId);
                }

            }

            return true;
        }