예제 #1
0
        public ActionResult View(int?season, int?turn, bool?print)
        {
            if (season.HasValue == false)
            {
                // find out current season
                season = DocumentSession.LatestSeasonOrDefault(SystemTime.UtcNow.Year);
            }

            if (turn.HasValue == false)
            {
                // find out next turn
                var rosters = DocumentSession.Query <Roster, RosterSearchTerms>()
                              .Where(x => x.Season == season)
                              .Where(x => x.Date > SystemTime.UtcNow.Date)
                              .OrderBy(x => x.Date)
                              .Take(1)
                              .ToList();
                turn = rosters.Select(x => x.Turn).FirstOrDefault();
            }

            Roster[] rostersForTurn = DocumentSession.Query <Roster, RosterSearchTerms>()
                                      .Include(roster => roster.Players)
                                      .Where(roster => roster.Turn == turn && roster.Season == season)
                                      .ToArray();
            RosterViewModel[] rosterViewModels = rostersForTurn.Select(DocumentSession.LoadRosterViewModel)
                                                 .SortRosters()
                                                 .ToArray();

            if (rosterViewModels.Length <= 0)
            {
                var vm = new InitialDataViewModel(
                    new InitialDataViewModel.ScheduledItem[0],
                    season.Value,
                    true);
                return(View("Unscheduled", vm));
            }

            var viewTurnViewModel = new ViewTurnViewModel(
                turn.Value,
                season.Value,
                rosterViewModels,
                true,
                TenantConfiguration.AppleTouchIcon);

            if (print.GetValueOrDefault())
            {
                return(View("Print", viewTurnViewModel));
            }

            return(View(viewTurnViewModel));
        }
예제 #2
0
        public ActionResult Print(
            int season,
            int turn,
            bool pdf,
            bool excludePast,
            bool withAbsence,
            bool excludePreliminary)
        {
            Roster[] rostersForTurn = DocumentSession.Query <Roster, RosterSearchTerms>()
                                      .Include(roster => roster.Players)
                                      .Where(roster => roster.Turn == turn && roster.Season == season)
                                      .ToArray()
                                      .Where(roster => (roster.Preliminary == false || excludePreliminary == false) &&
                                             (roster.Date.Date >= SystemTime.UtcNow || excludePast == false))
                                      .ToArray();
            RosterViewModel[] rosterViewModels = rostersForTurn.Select(DocumentSession.LoadRosterViewModel)
                                                 .SortRosters()
                                                 .ToArray();

            var viewTurnViewModel = new ViewTurnViewModel(
                turn,
                season,
                rosterViewModels,
                withAbsence,
                TenantConfiguration.AppleTouchIcon);

            if (pdf)
            {
                string filename = $"Uttagningar-{season}-{turn}.pdf";
                var    customSwitchesBuilder = new StringBuilder();
                customSwitchesBuilder.Append($"--footer-left \"Filnamn: {filename}\"");
                customSwitchesBuilder.Append(" --footer-right \"Sida [page] av [toPage]\"");
                customSwitchesBuilder.Append(" --footer-font-size \"8\"");
                customSwitchesBuilder.Append(" --footer-line");
                customSwitchesBuilder.Append(" --footer-spacing \"3\"");
                customSwitchesBuilder.Append($" --header-left \"{TenantConfiguration.FullTeamName}\"");
                customSwitchesBuilder.Append($" --header-center \"Omgång {turn}\"");
                customSwitchesBuilder.Append($" --header-right \"{DateTime.Now.Date.ToShortDateString()}\"");
                customSwitchesBuilder.Append(" --header-line");
                string customSwitches = customSwitchesBuilder.ToString();
                return(new ViewAsPdf(viewTurnViewModel)
                {
                    PageSize = Size.A4,
                    FileName = filename,
                    CustomSwitches = customSwitches
                });
            }

            return(View(viewTurnViewModel));
        }