internal void IncrementBy(FptsAllowed fptsAllowed)
 {
     ToQbs += fptsAllowed.ToQbs;
     ToRbs += fptsAllowed.ToRbs;
     ToWrs += fptsAllowed.ToWrs;
     ToTes += fptsAllowed.ToTes;
     ToPks += fptsAllowed.ToPks;
 }
 internal void Add(FptsAllowed fptsAllowed)
 {
     ToQbs += fptsAllowed.ToQbs;
     ToRbs += fptsAllowed.ToRbs;
     ToWrs += fptsAllowed.ToWrs;
     ToTes += fptsAllowed.ToTes;
     ToPks += fptsAllowed.ToPks;
 }
        private FptsAllowed GetFptsFor(string teamCode)
        {
            FptsAllowed fpts = null;

            foreach (FptsAllowed item in TotalFpAllowedList)
            {
                if (item.TeamCode.Equals(teamCode))
                {
                    fpts = item;
                    break;
                }
            }
            return(fpts);
        }
        private void AccumulateFptsAllowed(FptsAllowed fptsAllowed)
        {
            // get the right object
            var fpts = GetFptsFor(fptsAllowed.TeamCode);

            if (fpts == null)
            {
                TotalFpAllowedList.Add(fptsAllowed);
            }
            else
            {
                fpts.IncrementBy(fptsAllowed);
            }
        }
        private FptsAllowed CalculateFptsAllowed(
            NflTeam team,
            string theWeek,
            DataSet gameDs)
        {
            // Process Stats and Scores for the week
            // save the calculations
            var ftpsAllowed = new FptsAllowed(team.TeamCode);
            var game        = new NFLGame(gameDs.Tables[0].Rows[0]);

            List <NFLPlayer> playerList = new List <NFLPlayer>();

            if (game.IsAway(team.TeamCode))
            {
                playerList = game.LoadAllFantasyHomePlayers(
                    (DateTime?)game.GameDate,
                    String.Empty);
            }
            else
            {
                playerList = game.LoadAllFantasyAwayPlayers(
                    ( DateTime? )game.GameDate,
                    String.Empty);
            }

            var week = new NFLWeek(Season, theWeek);

            var scorer = new YahooXmlScorer(week);

            foreach (var p in playerList)
            {
                var plyrPts = scorer.RatePlayer(p, week);

                if (p.IsQuarterback())
                {
                    ftpsAllowed.ToQbs += plyrPts;
                    AddBreakdownLine(team, theWeek, p, plyrPts, "QB");
                }
                else if (p.IsRb())
                {
                    ftpsAllowed.ToRbs += plyrPts;
                    AddBreakdownLine(team, theWeek, p, plyrPts, "RB");
                }
                else if (p.IsWideout())
                {
                    ftpsAllowed.ToWrs += plyrPts;
                    AddBreakdownLine(team, theWeek, p, plyrPts, "WR");
                }
                else if (p.IsTe())
                {
                    ftpsAllowed.ToTes += plyrPts;
                    AddBreakdownLine(team, theWeek, p, plyrPts, "TE");
                }
                else if (p.IsKicker())
                {
                    ftpsAllowed.ToPks += plyrPts;
                    AddBreakdownLine(team, theWeek, p, plyrPts, "PK");
                }
            }

            return(ftpsAllowed);
        }
        private void LoadDataTable()
        {
#if DEBUG2
            var tCount = 0;
#endif
            var asOfWeek = int.Parse(Week);
            foreach (KeyValuePair <string, NflTeam> teamPair in TeamList)
            {
                var team = teamPair.Value;

                FptsAllowed fptsAllowed      = new FptsAllowed(team.TeamCode);
                FptsAllowed totalFptsAllowed = new FptsAllowed(team.TeamCode);

                for (var w = Constants.K_WEEKS_IN_REGULAR_SEASON; w > 0; w--)
                {
                    if (w > asOfWeek)
                    {
                        continue;
                    }
                    string theWeek = string.Format("{0:0#}", w);

                    var ds = Utility.TflWs.GameForTeam(
                        Season,
                        theWeek,
                        team.TeamCode);
                    if (ds.Tables[0].Rows.Count != 1)
                    {
                        continue;
                    }

                    fptsAllowed = CalculateFptsAllowed(team, theWeek, ds);

                    totalFptsAllowed.Add(fptsAllowed);
                    AccumulateFptsAllowed(fptsAllowed);
                }
                DumpBreakdowns(team.TeamCode);

#if DEBUG2
                tCount++;
                if (tCount > 0)
                {
                    break;
                }
#endif
            }

            RankTotalPoints();
            RankPointsToQbs();
            RankPointsToRbs();
            RankPointsToWrs();
            RankPointsToTes();
            RankPointsToPks();

            //  Build the output table
            foreach (FptsAllowed item in TotalFpAllowedList)
            {
                DataRow teamRow = Data.NewRow();
                teamRow["TEAM"]  = item.TeamCode;
                teamRow["TOTAL"] = 0;
                teamRow["QB"]    = LinkFor(item.TeamCode, "QB", item.ToQbs, item.ToQbsRank);
                teamRow["RB"]    = LinkFor(item.TeamCode, "RB", item.ToRbs, item.ToRbsRank);
                teamRow["WR"]    = LinkFor(item.TeamCode, "WR", item.ToWrs, item.ToWrsRank);
                teamRow["TE"]    = LinkFor(item.TeamCode, "TE", item.ToTes, item.ToTesRank);
                teamRow["PK"]    = LinkFor(item.TeamCode, "PK", item.ToPks, item.ToPksRank);

                teamRow["TOTAL"] = item.TotPtsAllowed();
                Data.Rows.Add(teamRow);
            }
        }