Ejemplo n.º 1
0
 private static ScheduleGameRowModel<IScheduleGameRowDataModel> GameHeaderRowFromGame(Game game)
 {
     return new ScheduleGameRowModel<IScheduleGameRowDataModel>
            {
                LabelData = new ScheduleGameHeaderModel
                            {
                                DisplayOutcome = game.GameStatus.DisplayOutcome,
                                Outcome = game.GameStatus.Description,
                                GameDate = game.GameDate
                            },
                GameId = game.GameId,
                DisplayScores = game.GameStatus.IsComplete,
                Runs = "R",
                Hits = "H"
            };
 }
Ejemplo n.º 2
0
        private ScheduleGameModel GameModelFromGame(Game game)
        {
            var teamRows = game.GameParticipants
                               .OrderBy(gp => gp.IsHost)
                               .Select(GameTeamRowModelFromParticipant)
                               .ToList();

            if (!teamRows[0].Runs.Equals(teamRows[1].Runs))
            {
                teamRows.OrderByDescending(tr => tr.Runs)
                        .First()
                        .IsWinner = true;
            }

            return new ScheduleGameModel
                   {
                       HeaderRow = GameHeaderRowFromGame(game),
                       RoadTeamRow = teamRows[0],
                       HomeTeamRow = teamRows[1]
                   };
        }
Ejemplo n.º 3
0
        private void PopulateDropdownLists(GameResultsEditCreateReportModel model, Game game)
        {
            var teams = game.GameParticipants
                            .Select(gp => gp.TeamYear)
                            .OrderBy(ty => ty.FullName);

            var teamModels = new[] { new TeamBasicInfoModel { FullName = Consts.LeagueNameForList } }
                                 .Concat(Mapper.Map<List<TeamBasicInfoModel>>(teams))
                                 .FilterTeamsForUser(User, m => m.TeamId)
                                 .ToList();
            model.Team.TeamId = teamModels.Count == 1 ? teamModels[0].TeamId : null;
            model.Team.ItemSelectList = new SelectList(teamModels, "TeamId", "FullName", model.Team.TeamId);

            model.GameStatus.ItemSelectList = GetGameStatusesSelectListItems(null, true);
        }
Ejemplo n.º 4
0
        private bool CanFinalize(Game game)
        {
            var reportData = game.GameResultReports
                                 .OrderByDescending(r => r.Created)
                                 .Select(r => new
                                              {
                                                  r.IsConfirmation,
                                                  r.TeamId
                                              })
                                 .ToList();

            var reportingTeamIds = reportData.Take(reportData.FindIndex(d => !d.IsConfirmation) + 1)
                                             .Where(d => d.TeamId.HasValue)
                                             .Select(d => d.TeamId.Value)
                                             .ToList();

            return game.GameParticipants
                       .Select(gp => gp.TeamYear.TeamId)
                       .ToList()
                       .All(reportingTeamIds.Contains);
        }
Ejemplo n.º 5
0
        private static GameBucket GetGameBucket(Game game)
        {
            if (game.GameTypeId == GameType.GamePlaceholder)
            {
                return new GameBucket("Post-Season", 0);
            }

            if (Consts.TournamentDates.Contains(game.GameDate.Date))
            {
                return new GameBucket(game.GameDate.ToString("t"), (int)game.GameDate.TimeOfDay.TotalMinutes);
            }

            var conferences = game.GameParticipants
                                  .Select(gp => gp.TeamYear.DivisionYear.ConferenceYear)
                                  .DistinctBy(cy => cy.ConferenceYearId)
                                  .ToList();

            if (game.GameTypeId == GameType.Exhibition || conferences.Any(cy => !cy.IsInLeague))
            {
                return new GameBucket("Exhibition", 99);
            }

            if (conferences.Count > 1 && conferences[0].ConferenceYearId != conferences[1].ConferenceYearId)
            {
                return new GameBucket("Inter-Conference", 90);
            }

            return new GameBucket(conferences[0].Name, conferences[0].Sort);
        }
Ejemplo n.º 6
0
        public static GameBucket GetGameBucketForEdit(Game game, bool singleDate)
        {
            var sortBase = singleDate ? 0 : -game.GameDate.DayOfYear * 10000;
            var prefix = singleDate ? "" : game.GameDate.ToString("MMMM d, ");

            if (game.GameTypeId == GameType.GamePlaceholder)
            {
                return new GameBucket($"{prefix}Post-Season", sortBase + 9998);
            }

            if (Consts.TournamentDates.Contains(game.GameDate.Date))
            {
                return new GameBucket($"{prefix}{game.GameDate:t}", sortBase + (int)game.GameDate.TimeOfDay.TotalMinutes);
            }

            var conferences = game.GameParticipants
                                  .Select(gp => gp.TeamYear.DivisionYear.ConferenceYear)
                                  .DistinctBy(cy => cy.ConferenceYearId)
                                  .ToList();

            if (game.GameTypeId == GameType.Exhibition || conferences.Any(cy => !cy.IsInLeague))
            {
                return new GameBucket($"{prefix}Exhibition", sortBase + 9999);
            }

            if (conferences.Count > 1 && conferences[0].ConferenceYearId != conferences[1].ConferenceYearId)
            {
                return new GameBucket($"{prefix}Inter-Conference", sortBase + 9990);
            }

            return new GameBucket($"{prefix}{conferences[0].Name}", sortBase + conferences[0].Sort);
        }