Beispiel #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));
        }
        public Task <InitialDataViewModel> GetInitialDataAsync(int year, int month)
        {
            return(Task.Factory.StartNew(() =>
            {
                var initialData = new InitialDataViewModel();
                initialData.Calendar.Users = _vacationService.GetUsersDataIncludeVacation(year, month, "", "", null);
                initialData.Calendar.Year = year;
                initialData.Calendar.Month = month;
                initialData.Calendar.MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month);

                initialData.StaticLists = _staticListsService.GetStaticLists();

                return initialData;
            }));
        }
Beispiel #3
0
        public ActionResult Index(int?season)
        {
            bool selectAll = true;

            if (season.HasValue == false)
            {
                season    = DocumentSession.LatestSeasonOrDefault(SystemTime.UtcNow.Year);
                selectAll = false;
            }

            var rosters = DocumentSession.Query <Roster, RosterSearchTerms>()
                          .Where(r => r.Season == season)
                          .ToList();
            IEnumerable <InitialDataViewModel.TurnViewModel> q = from roster in rosters
                                                                 orderby roster.Turn
                                                                 group roster by roster.Turn
                                                                 into g
                                                                 let lastDate = g.Max(x => x.Date)
                                                                                where selectAll || lastDate >= SystemTime.UtcNow.Date
                                                                                select new InitialDataViewModel.TurnViewModel(
                seasonStart: season.Value,
                turn: g.Key,
                startDate: g.Min(x => x.Date),
                endDate: lastDate,
                rosters: g.Select(x => new RosterViewModel(
                                      x,
                                      new RosterViewModel.PlayerItem(string.Empty, string.Empty, false),
                                      new List <RosterViewModel.PlayerItem>()))
                .SortRosters()
                .ToArray());

            InitialDataViewModel.TurnViewModel[]             turns      = q.ToArray();
            IEnumerable <InitialDataViewModel.ScheduledItem> activities =
                DocumentSession.Query <Activity, ActivityIndex>()
                .Where(x => x.Season == season.Value)
                .ToArray()
                .Where(x => selectAll || x.Date >= SystemTime.UtcNow.Date.AddDays(-3))
                .Select(x => new InitialDataViewModel.ScheduledActivityItem(x.Id, x.Title, x.Date, x.MessageHtml, string.IsNullOrEmpty(x.AuthorId) == false ? DocumentSession.Load <Player>(x.AuthorId)?.Name ?? string.Empty : string.Empty));
            bool isFiltered = rosters.Count != turns.Sum(x => x.Rosters.Length);
            var  vm         = new InitialDataViewModel(turns.Concat(activities).OrderBy(x => x.Date).ToArray(), season.Value, isFiltered);

            if (turns.Length <= 0)
            {
                return(View("Unscheduled", vm));
            }
            return(View(vm));
        }