protected PlayerSeasonStats AddPlayerSeasonStats(Player player, Season season, int totalPoints, int totalFouls, int gamesPlayed, int mvpAwards)
        {
            PlayerSeasonStats stats = new PlayerSeasonStats(player, season, totalPoints, totalFouls, gamesPlayed, mvpAwards);

            //statsRepository.SaveOrUpdatePlayerSeasonStats(stats);
            //FlushSessionAndEvict(stats);
            return(stats);
        }
예제 #2
0
        public static PlayerSeasonStats CreatePlayerSeasonStats(int id, Player player, Season season)
        {
            PlayerSeasonStats p = new PlayerSeasonStats(player, season, 100, 20, 5, 1);

            EntityIdSetter.SetIdOf(p, id);

            return(p);
        }
예제 #3
0
        public static PlayerSeasonStats CreatePlayerSeasonStats()
        {
            PlayerSeasonStats p = new PlayerSeasonStats(CreatePlayer(), CreateSeason(), 100, 20, 5, 1);

            EntityIdSetter.SetIdOf(p, 1);

            return(p);
        }
 public PlayerCareerStatsDto(PlayerSeasonStats playerSeasonStats)
 {
     this.Year          = string.Format("{0}/{1}", playerSeasonStats.Season.StartYear, playerSeasonStats.Season.EndYear);
     this.Games         = playerSeasonStats.GamesPlayed.ToString();
     this.MvpAwards     = playerSeasonStats.MvpAwards.ToString();
     this.Fouls         = playerSeasonStats.TotalFouls.ToString();
     this.FoulsPerGame  = playerSeasonStats.FoulsPerGame.ToString("0.00");
     this.Points        = playerSeasonStats.TotalPoints.ToString();
     this.PointsPerGame = playerSeasonStats.PointsPerGame.ToString("0.00");
 }
예제 #5
0
 public ActionResult Edit(PlayerSeasonStats @playerSeasonStats)
 {
     if (ModelState.IsValid)
     {
         playerSeasonStatsService.Update(@playerSeasonStats);
         playerSeasonStatsService.Commit();
         SuccessMessage(FormMessages.SaveSuccess);
         return(RedirectToAction("Index"));
     }
     return(View(@playerSeasonStats));
 }
        public void CanCreatePlayerSeasonStatsWithZeroGamesPlayed()
        {
            Season season      = new Season(2009, 2010);
            Player player      = new Player("Phil", "Hale");
            int    totalPoints = -2;
            int    totalFouls  = 2;
            int    gamesPlayed = 0;
            int    mvpAwards   = 5;

            PlayerSeasonStats stats = new PlayerSeasonStats(player, season, 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));
        }
        // Delete existing records that have been marked as not played
        //statsService.DeleteExistingPlayerFixturesThatDidNotPlay(homePlayerStats, homeHasPlayed);
        //statsService.DeleteExistingPlayerFixturesThatDidNotPlay(awayPlayerStats, awayHasPlayed);

        //// Remove players that did not player from the list so we only update those who played
        //RemovePlayersThatDidNotPlay(homePlayerStats, homeHasPlayed);
        //RemovePlayersThatDidNotPlay(awayPlayerStats, awayHasPlayed);

        //// Save player fixture records. Pass whether each player has played so players that haven't played are not
        //// updated. If this wasn't passed in the PlayerFixture records would be delete by the method call above then
        //// inserted again by the call below

        //// The logic is a bit odd here. All players, played or unplayed must be passed to the update
        //// season/league/career methods so they are always update (e.g. if a PlayerFixture record is saved then marked
        //// unplayed it is deleted, but the player record must still be passed to the update stats method to recalculate
        //// the stats
        //statsService.InsertOrUpdatePlayerFixturesThatHavePlayed(homePlayerStats, homeHasPlayed);
        //statsService.InsertOrUpdatePlayerFixturesThatHavePlayed(awayPlayerStats, awayHasPlayed);
        ////statsService.Commit();

        //// Update player league stats
        //statsService.UpdatePlayerLeagueStats(homePlayerStats, fixtureToUpdate.HomeTeamLeague.League);
        //statsService.UpdatePlayerLeagueStats(awayPlayerStats, fixtureToUpdate.HomeTeamLeague.League);

        //// Update player season stats
        //Season currentSeason = GetCurrentSeason();
        //statsService.UpdatePlayerSeasonStats(homePlayerStats, currentSeason);
        //statsService.UpdatePlayerSeasonStats(awayPlayerStats, currentSeason);

        //// Update player career stats
        //statsService.UpdatePlayerCareerStats(homePlayerStats);
        //statsService.UpdatePlayerCareerStats(awayPlayerStats);

        //// Update team stats
        //UpdateTeamLeagueStats(fixtureToUpdate.HomeTeamLeague.Id);
        //UpdateTeamLeagueStats(fixtureToUpdate.AwayTeamLeague.Id);

        #endregion

        public PlayerSeasonStats UpdatePlayerSeasonStats(PlayerFixture playerFixture, Season season)
        {
            PlayerSeasonStats playerSeasonStats;
            int totalPoints = 0;
            int totalFouls  = 0;
            int mvpAwards   = 0;

            // Get all PlayerFixture records for specified season
            List <PlayerFixture> playerFixturesForSeason = this.statsReportingService.GetPlayerFixtureStatsForSeason(playerFixture.Player.Id, season.Id).ToList();

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

            // Find existing record
            playerSeasonStats = this.statsReportingService.GetPlayerSeasonStats(playerFixture.Player.Id, season.Id);

            // If doesn't exist, create new
            if (playerSeasonStats == null)
            {
                playerSeasonStats = new PlayerSeasonStats(playerFixture.Player, season, totalPoints, totalFouls, playerFixturesForSeason.Count, mvpAwards);
            }
            else
            {
                // Update values
                playerSeasonStats.UpdateStats(totalPoints, totalFouls, playerFixturesForSeason.Count, mvpAwards);
            }

            // Save
            matchResultRepository.SavePlayerSeasonStats(playerSeasonStats);

            return(playerSeasonStats);
        }
예제 #8
0
 public PlayerSeasonStats SavePlayerSeasonStats(PlayerSeasonStats playerSeasonStats)
 {
     playerSeasonStatsRepository.InsertOrUpdate(playerSeasonStats);
     return(playerSeasonStats);
 }
예제 #9
0
        public ActionResult Edit(int id)
        {
            PlayerSeasonStats @playerSeasonStats = playerSeasonStatsService.Get(id);

            return(View(@playerSeasonStats));
        }