コード例 #1
0
        public ActionResult ListEligibleKeepers(string teamKey)
        {
            var teamPlayers = this.Fantasizer.GetTeamPlayerStats(teamKey);
            var draftResults = this.Fantasizer.GetDraftResults(teamPlayers.Team.LeagueKey);

            // TODO: This block is mostly duplicated with the LeagueController's DownloadEligibleKeepers action.
            LeagueDao leagueData;
            using (var session = _sessionFactory.OpenSession())
            {
                leagueData = session.Get<LeagueDao>(draftResults.League.Key);
                if (leagueData == null || !leagueData.AllowKeepersFromPriorSeason.HasValue)
                {
                    TempData["UserAlertMessage"] = "You must specify your league's keeper settings before proceeding.";
                    return RedirectToAction("ViewKeeperSettings", "League", new { leagueKey = draftResults.League.Key});
                }
            }

            var keeperAnalyzer = new KeeperAnalyzer(teamPlayers, draftResults, leagueData.AllowKeepersFromPriorSeason.Value);
            var keepers = keeperAnalyzer.GetEligibleKeepersForTeam(teamKey);
            var sortedKeepers = keepers.OrderBy(k => k.DraftRound);

            var model = new EligibleKeeperModel()
            {
                Team = teamPlayers.Team,
                EligibleKeepers = sortedKeepers
            };

            return View(model);
        }
コード例 #2
0
        public ActionResult DownloadEligibleKeepers(string leagueKey)
        {
            var leagueTeamPlayers = this.Fantasizer.GetLeagueTeamPlayers(leagueKey);
            var draftResults = this.Fantasizer.GetDraftResults(leagueKey);

            // TODO: This block is mostly duplicated with the TeamController's ListEligibleKeepers action.
            LeagueDao leagueData;
            using (var session = _sessionFactory.OpenSession())
            {
                leagueData = session.Get<LeagueDao>(draftResults.League.Key);
                if (leagueData == null || !leagueData.AllowKeepersFromPriorSeason.HasValue)
                {
                    TempData["UserAlertMessage"] = "You must specify your league's keeper settings before proceeding.";
                    return RedirectToAction("ViewKeeperSettings", "League", new { leagueKey = draftResults.League.Key });
                }
            }

            var keepers = new KeeperAnalyzer(leagueTeamPlayers, draftResults, leagueData.AllowKeepersFromPriorSeason.Value);
            var writer = new EligibleKeeperWriter(keepers.GetEligibleKeepersForLeague(leagueKey));

            return File(writer.ToCsvArray(), "text/csv", "eligible-keepers.csv");
        }