public void CanCreatePlayerLeagueStatsWithZeroGamesPlayed()
        {
            int totalPoints = -2;
            int totalFouls = 2;
            int gamesPlayed = 0;
            int mvpAwards = 2;

            PlayerLeagueStats stats = new PlayerLeagueStats(player, season, league, totalPoints, totalFouls, gamesPlayed, mvpAwards);

            Assert.IsNotNull(stats);
            Assert.That(stats.Season, Is.EqualTo(season));
            Assert.That(stats.Player, Is.EqualTo(player));
            Assert.That(stats.GamesPlayed, Is.EqualTo(0));
            Assert.That(stats.TotalPoints, Is.EqualTo(0));
            Assert.That(stats.PointsPerGame, Is.EqualTo(0));
            Assert.That(stats.TotalFouls, Is.EqualTo(0));
            Assert.That(stats.FoulsPerGame, Is.EqualTo(0));
            Assert.That(stats.MvpAwards, Is.EqualTo(mvpAwards));
        }
        public void CanCreatePlayerLeagueStats()
        {
            int totalPoints = 50;
            int totalFouls = 10;
            int gamesPlayed = 4;
            int mvpAwards = 10;

            PlayerLeagueStats stats = new PlayerLeagueStats(player, season, league, totalPoints, totalFouls, gamesPlayed, mvpAwards);

            Assert.IsNotNull(stats);
            Assert.That(stats.Season, Is.EqualTo(season));
            Assert.That(stats.Player, Is.EqualTo(player));
            Assert.That(stats.League, Is.EqualTo(league));
            Assert.That(stats.TotalPoints, Is.EqualTo(totalPoints));
            Assert.That(stats.PointsPerGame, Is.EqualTo(12.5f));
            Assert.That(stats.TotalFouls, Is.EqualTo(totalFouls));
            Assert.That(stats.FoulsPerGame, Is.EqualTo(2.5f));
            Assert.That(stats.GamesPlayed, Is.EqualTo(gamesPlayed));
            Assert.That(stats.MvpAwards, Is.EqualTo(mvpAwards));
        }
        protected PlayerLeagueStats AddPlayerLeagueStats(Player player, Season season, League league, int totalPoints, int totalFouls, int gamesPlayed, int mvpAwards)
        {
            PlayerLeagueStats stats = new PlayerLeagueStats(player, season, league, totalPoints, totalFouls, gamesPlayed, mvpAwards);

            //statsRepository.SaveOrUpdatePlayerLeagueStats(stats);
            //FlushSessionAndEvict(stats);
            return stats;
        }
 private string OutputStats(string statsOutput, PlayerLeagueStats pls, string playerStat)
 {
     // Link is hardcoded rather that using the help which isn't great
     return statsOutput + "<a title=\"Click to view player stats\" href=\"/Stats/Player?id=" + pls.Player.Id + "\">" + pls.Player.ShortName + "</a> " + playerStat + ", ";
 }
        public PlayerLeagueStats UpdatePlayerLeagueStats(PlayerFixture playerFixture, League league)
        {
            PlayerLeagueStats playerLeagueStats;
            int totalPoints = 0;
            int totalFouls = 0;
            int mvpAwards = 0;

            // Get all PlayerFixture records for specified league
            List<PlayerFixture> playerFixturesForLeague = this.statsReportingService.GetPlayerFixturesForLeagueAndPlayer(playerFixture.Player.Id, league.Id).ToList();

            // Total stats
            foreach (PlayerFixture pf in playerFixturesForLeague)
            {
                totalPoints += pf.PointsScored;
                totalFouls += pf.Fouls;
                if (pf.IsMvp == "Y")
                    mvpAwards++;
            }

            // Find existing record
            playerLeagueStats = this.statsReportingService.GetPlayerLeagueStats(playerFixture.Player.Id, league.Id);

            // Getting the play
            // If doesn't exist, create new
            if (playerLeagueStats == null)
                playerLeagueStats = new PlayerLeagueStats(playerFixture.Player, league.Season, league, totalPoints, totalFouls, playerFixturesForLeague.Count, mvpAwards);
            else
            {
                // Update values
                playerLeagueStats.UpdateStats(totalPoints, totalFouls, playerFixturesForLeague.Count, mvpAwards);
            }

            // Save
            matchResultRepository.SavePlayerLeagueStats(playerLeagueStats);

            return playerLeagueStats;
        }
 public ActionResult Edit(PlayerLeagueStats @playerLeagueStats)
 {
     if (ModelState.IsValid) {
                 playerLeagueStatsService.Update(@playerLeagueStats);
                 playerLeagueStatsService.Commit();
                 SuccessMessage(FormMessages.SaveSuccess);
                 return RedirectToAction("Index");
         }
         return View(@playerLeagueStats);
 }
 public PlayerLeagueStats SavePlayerLeagueStats(PlayerLeagueStats playerLeagueStats)
 {
     playerLeagueStatsRepository.InsertOrUpdate(playerLeagueStats);
     return playerLeagueStats;
 }