public static void WriteUserTeamCupToDB(int pageId, UserTeamCupMatches userTeamCupInsert, SqlConnection db)
        {
            try
            {
                UserTeamCupRepository userTeamCupRepository = new UserTeamCupRepository();

                //Write UserTeamCup to the db
                Globals.UserTeamCupRowsInserted = userTeamCupRepository.InsertUserTeamCup(userTeamCupInsert, db);
                Logger.Out("UserTeamCup bulk insert complete (PageId: " + Convert.ToString(pageId) + ")");

                userTeamCupInsert.Clear();
            }
            catch (Exception ex)
            {
                Logger.Error("Program WriteUserTeamCupToDB error: " + ex.Message);
            }
        }
        public static void GetUserTeamCupJson(int userTeamId, UserTeam userTeam, UserTeamCupMatches userTeamCupInsert, SqlConnection db)
        {
            try
            {
                //Load Cup data
                UserTeamCupRepository cupRepository = new UserTeamCupRepository();

                //List<int> CupIds = cupRepository.GetAllCupIdsForUserId(userTeamId, db);

                //int cupid, gameweekid;

                foreach (UserTeamCupMatch match in userTeam.leagues.cup.matches)
                {
                    match.fromuserteamid = userTeamId;

                    //if (!CupIds.Contains(match.id) && match.@event < Globals.LatestGameweek)
                    if (match.@event < Globals.LatestGameweek)
                    {
                        //cupRepository.InsertUserTeamCup(match, db);
                        userTeamCupInsert.Add(match);
                        Logger.Out("Cup: " + match.entry_1_name + " v " + match.entry_2_name + " - added");
                    }
                    //else
                    //{
                    //    cupRepository.UpdateUserTeamCup(match, db);
                    //}

                    //if (match.tiebreak != null)
                    //{
                    //    cupid = match.id;
                    //    gameweekid = match.@event;
                    //    GetUserTeamCupTiebreakJson(userTeamId, cupid, gameweekid, cup);
                    //}
                }
            }
            catch (Exception ex)
            {
                Logger.Error("GetUserTeamCupJson data exception (UserTeamId: " + userTeamId.ToString() + "): " + ex.Message);
                //throw new Exception("GetUserTeamCupJson data exception (UserTeamId: " + userTeamId.ToString() + "): " + ex.Message);
                //GetUserTeamCupJson(userTeamId, userTeamHistoryData);
            }
        }
        public static void GetUserTeamCupJson(int userTeamId, UserTeam userTeam, SqlConnection db)
        {
            try
            {
                //Load Cup data
                UserTeamCupRepository cupRepository = new UserTeamCupRepository();

                List <int> CupIds = cupRepository.GetAllCupIdsForUserId(userTeamId, db);

                int cupid, gameweekid;

                foreach (UserTeamCupMatch match in userTeam.leagues.cup.matches)
                {
                    match.fromuserteamid = userTeamId;

                    if (!CupIds.Contains(match.id))
                    {
                        cupRepository.InsertUserTeamCup(match, db);
                    }
                    else
                    {
                        cupRepository.UpdateUserTeamCup(match, db);
                    }

                    if (match.tiebreak != null)
                    {
                        cupid      = match.id;
                        gameweekid = match.@event;
                        //GetUserTeamCupTiebreakJson(userTeamId, cupid, gameweekid, cup);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("GetUserTeamCupJson data exception (UserTeamId: " + userTeamId.ToString() + "): " + ex.Message);
                throw new Exception("GetUserTeamCupJson data exception (UserTeamId: " + userTeamId.ToString() + "): " + ex.Message);
                //GetUserTeamCupJson(userTeamId, userTeamHistoryData);
            }
        }