public void given_weekly_scores_for_each_team_when_determining_the_team_points_for_each_team_for_the_second_week_summary_report_then_assign_points_according_to_rules_using_initial_averages_to_calculate_handicap()
        {
            TeamPoints teamPoints = new TeamPoints();
            Week week1 = CreateWeek(1, "week1");
            Week week2 = CreateWeek(2, "week2");
            Team team1 = CreateTeam("team1");
            Team team2 = CreateTeam("team2");
            Player player1 = CreatePlayer("M", 1, "p1", team1, 150);
            Player player2 = CreatePlayer("M", 2, "p2", team1, 120);
            Player player3 = CreatePlayer("M", 3, "p3", team2, 150);
            Player player4 = CreatePlayer("M", 4, "p4", team2, 150);
            List<WeeklyScore> team1Scores = new List<WeeklyScore>();
            List<WeeklyScore> team2Scores = new List<WeeklyScore>();
            List<Player> players = new List<Player> {player1, player2, player3, player4};

            WeeklyScore score1 = CreateWeeklyScore(100, 150, 100, player1, team1, week1, false);
            WeeklyScore score2 = CreateWeeklyScore(120, 120, 120, player2, team1, week1, false);
            WeeklyScore score3 = CreateWeeklyScore(110, 110, 110, player3, team2, week1, false);
            WeeklyScore score4 = CreateWeeklyScore(130, 115, 130, player4, team2, week1, false);

            team1Scores.Add(score1);
            team1Scores.Add(score2);
            team2Scores.Add(score3);
            team2Scores.Add(score4);

            teamPoints.UpdatePointsForTeam(team1Scores, team2Scores, week1, team1, team2, players);

            List<WeeklyPoint> team1WeeklyPoints = team1.WeeklyPoints.Where(p => p.Week == week1).ToList();
            Assert.That(team1WeeklyPoints.Count, Is.EqualTo(1));
            Assert.That(team1WeeklyPoints[0].Points, Is.EqualTo(4));

            List<WeeklyPoint> team2WeeklyPoints = team2.WeeklyPoints.Where(p => p.Week == week1).ToList();
            Assert.That(team2WeeklyPoints.Count, Is.EqualTo(1));
            Assert.That(team2WeeklyPoints[0].Points, Is.EqualTo(0));
        }
        public void SaveWeeklyScores()
        {
            if (SelectedWeek == null)
            {
                return;
            }

            UpdateScoresForThisWeek();

            TeamPoints teamPoints = new TeamPoints();

            IEnumerable<WeeklyMatchup> thisWeeksMatchups = _matchups.Where(m => m.Week.Equals(SelectedWeek));

            foreach (WeeklyMatchup weeklyMatchup in thisWeeksMatchups)
            {
                WeeklyMatchup matchup = weeklyMatchup;
                Team team1 = _teams.Find(t => t.Equals(matchup.TeamOne));
                Team team2 = _teams.Find(t => t.Equals(matchup.TeamTwo));
                List<WeeklyScore> team1Scores = _allScores.Where(s => s.Team.Equals(team1)).ToList();
                List<WeeklyScore> team2Scores = _allScores.Where(s => s.Team.Equals(team2)).ToList();
                teamPoints.UpdatePointsForTeam(team1Scores, team2Scores, SelectedWeek, team1, team2, _players);
            }
        }
        private void SaveScores(Week week)
        {
            if (week == null)
            {
                return;
            }

            List<WeeklyScore> scores = (from gridPlayerViewModel in _gridPlayers
                                        let model = gridPlayerViewModel
                                        let player = _players.FirstOrDefault(p => p.Id == model.PlayerId)
                                        let team = _teams.FirstOrDefault(t => t.Name == model.TeamName)
                                        select
                                            new WeeklyScore
                                                {
                                                    Absent = gridPlayerViewModel.Absent,
                                                    Game1 = gridPlayerViewModel.Game1,
                                                    Game2 = gridPlayerViewModel.Game2,
                                                    Game3 = gridPlayerViewModel.Game3,
                                                    Player = player,
                                                    Team = team,
                                                    Week = SelectedWeek
                                                }).ToList();

            List<WeeklyScore> scoresToRemove = _allScores.Where(weeklyScore => weeklyScore.Week.WeekNumber == week.WeekNumber).ToList();

            foreach (WeeklyScore weeklyScore in scoresToRemove)
            {
                _allScores.Remove(weeklyScore);
            }

            _allScores.AddRange(scores);

            TeamPoints teamPoints = new TeamPoints();

            IEnumerable<WeeklyMatchup> thisWeeksMatchups = _matchups.Where(m => m.Week.Equals(SelectedWeek));

            foreach (WeeklyMatchup weeklyMatchup in thisWeeksMatchups)
            {
                WeeklyMatchup matchup = weeklyMatchup;
                Team team1 = _teams.Find(t => t.Equals(matchup.TeamOne));
                Team team2 = _teams.Find(t => t.Equals(matchup.TeamTwo));
                List<WeeklyScore> team1Scores = _allScores.Where(s => s.Team.Equals(team1)).ToList();
                List<WeeklyScore> team2Scores = _allScores.Where(s => s.Team.Equals(team2)).ToList();
                teamPoints.UpdatePointsForTeam(team1Scores, team2Scores, SelectedWeek, team1, team2, _players);
            }
        }