public async Task <SeasonInfoView> GetSeasonInfoView()
        {
            var view = new SeasonInfoView();
            //TODO: Uncomment when testing
            //var seasonInfoTask = _seasonInfoRepository.GetAllSeasonsAsync();

            //var seasons = (await seasonInfoTask).OrderByDescending(x => x.SeasonStartDate).ToList();
            //var seasonInfo = seasons[1];

            //TODO: Uncomment when ready to push
            var seasonInfo = await _seasonInfoRepository.GetCurrentSeasonAsync();

            var rostersTask = GetAllRosters(seasonInfo);

            var divisions = (await _divisionRepository.GetAllForSeasonAsync(seasonInfo.Id)).ToList();

            try
            {
                var rosters = (await rostersTask).ToList();

                foreach (var rosterView in rosters)
                {
                    var division = divisions.First(x =>
                                                   x.LowerLimit <= rosterView.TeamTierScore && x.UpperLimit >= rosterView.TeamTierScore);
                    rosterView.Division = new DivisionView
                    {
                        DivisionName     = division.Name,
                        DivisionMinScore = division.LowerLimit,
                        DivisionId       = division.Id
                    };
                }

                view.Rosters = rosters.OrderByDescending(x => x.Division.DivisionMinScore).ToList();
            }
            catch (Exception)
            {
                //no rosters finalized yet
            }

            view.SeasonInfo = new SeasonInfoViewPartial
            {
                SeasonInfoId           = seasonInfo.Id,
                ClosedRegistrationDate = seasonInfo.ClosedRegistrationDate,
                SeasonName             = seasonInfo.SeasonName,
                SeasonStartDate        = seasonInfo.SeasonStartDate
            };
            return(view);
        }
Exemplo n.º 2
0
        public async Task <Dictionary <string, List <ScheduleView> > > GetAllSchedules()
        {
            var seasonInfo = await _seasonInfoRepository.GetCurrentSeasonAsync();

            var divisionsTask = _divisionRepository.GetAllForSeasonAsync(seasonInfo.Id);
            var schedulesTask = _scheduleRepository.GetAllAsync(seasonInfo.Id);
            var rostersTask   = _teamRosterRepository.GetAllTeamsAsync(seasonInfo.Id);

            var rosters   = (await rostersTask).ToDictionary(x => x.Id, x => x);
            var divisions = (await divisionsTask).ToList();
            var schedules = (await schedulesTask).ToList();


            return(SetupSchedule(rosters, divisions, schedules));
        }