From 04607931f9404c8dbfc1e0f895c19cd3e4b283ed Mon Sep 17 00:00:00 2001 From: Kenny Young Date: Wed, 26 Sep 2018 21:29:18 -0700 Subject: [PATCH 1/2] Fix Play Page --- ServerCore/Pages/Teams/Play.cshtml | 4 ++-- ServerCore/Pages/Teams/Play.cshtml.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ServerCore/Pages/Teams/Play.cshtml b/ServerCore/Pages/Teams/Play.cshtml index 1fa5cf46..394fc35c 100644 --- a/ServerCore/Pages/Teams/Play.cshtml +++ b/ServerCore/Pages/Teams/Play.cshtml @@ -53,11 +53,11 @@ @Html.DisplayFor(modelItem => item.Puzzle.OrderInGroup) - @Html.DisplayFor(modelItem => item.Puzzle.PuzzleFile == null ? null : item.Puzzle.PuzzleFile.ShortName) + @Html.DisplayFor(modelItem => item.Puzzle.PuzzleFile.ShortName) @if (showAnswers) { - @Html.DisplayFor(modelItem => item.Puzzle.AnswerFile == null ? null : item.Puzzle.AnswerFile.ShortName) + @Html.DisplayFor(modelItem => item.Puzzle.AnswerFile.ShortName) } diff --git a/ServerCore/Pages/Teams/Play.cshtml.cs b/ServerCore/Pages/Teams/Play.cshtml.cs index 24625c78..710b70b0 100644 --- a/ServerCore/Pages/Teams/Play.cshtml.cs +++ b/ServerCore/Pages/Teams/Play.cshtml.cs @@ -36,7 +36,7 @@ public async Task OnGetAsync(int id, SortOrder? sort) this.Sort = sort; // all puzzles for this event that are real puzzles - var puzzlesInEventQ = _context.Puzzles.Where(puzzle => puzzle.Event.ID == this.Event.ID && puzzle.IsPuzzle); + var puzzlesInEventQ = _context.Puzzles.Include(puzzle => puzzle.Contents).Where(puzzle => puzzle.Event.ID == this.Event.ID && puzzle.IsPuzzle); // all puzzle states for this team that are unlocked (note: IsUnlocked bool is going to harm perf, just null check the time here) // Note that it's OK if some puzzles do not yet have a state record; those puzzles are clearly still locked and hence invisible. From f433a95c36169ae8432eae28b046386f9bec4e4d Mon Sep 17 00:00:00 2001 From: Kenny Young Date: Wed, 26 Sep 2018 21:51:18 -0700 Subject: [PATCH 2/2] Even more fixy --- ServerCore/Pages/Teams/Play.cshtml.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ServerCore/Pages/Teams/Play.cshtml.cs b/ServerCore/Pages/Teams/Play.cshtml.cs index 710b70b0..c94869f3 100644 --- a/ServerCore/Pages/Teams/Play.cshtml.cs +++ b/ServerCore/Pages/Teams/Play.cshtml.cs @@ -36,14 +36,15 @@ public async Task OnGetAsync(int id, SortOrder? sort) this.Sort = sort; // all puzzles for this event that are real puzzles - var puzzlesInEventQ = _context.Puzzles.Include(puzzle => puzzle.Contents).Where(puzzle => puzzle.Event.ID == this.Event.ID && puzzle.IsPuzzle); + var puzzlesInEventQ = _context.Puzzles.Where(puzzle => puzzle.Event.ID == this.Event.ID && puzzle.IsPuzzle); // all puzzle states for this team that are unlocked (note: IsUnlocked bool is going to harm perf, just null check the time here) // Note that it's OK if some puzzles do not yet have a state record; those puzzles are clearly still locked and hence invisible. var stateForTeamQ = _context.PuzzleStatePerTeam.Where(state => state.TeamID == id && state.UnlockedTime != null); // join 'em (note: just getting all properties for max flexibility, can pick and choose columns for perf later) - var visiblePuzzlesQ = puzzlesInEventQ.Join(stateForTeamQ, (puzzle => puzzle.ID), (state => state.PuzzleID), (puzzle, state) => new PuzzleWithState(puzzle, state)); + // Note: EF gotcha is that you have to join into anonymous types in order to not lose valuable stuff + var visiblePuzzlesQ = puzzlesInEventQ.Join(stateForTeamQ, (puzzle => puzzle.ID), (state => state.PuzzleID), (Puzzle, State) => new { Puzzle, State }); switch (sort ?? DefaultSort) { @@ -69,7 +70,7 @@ public async Task OnGetAsync(int id, SortOrder? sort) throw new ArgumentException($"unknown sort: {sort}"); } - PuzzlesWithState = await visiblePuzzlesQ.ToListAsync(); + PuzzlesWithState = (await visiblePuzzlesQ.ToListAsync()).Select(x => new PuzzleWithState(x.Puzzle, x.State)).ToList(); } public SortOrder? SortForColumnLink(SortOrder ascendingSort, SortOrder descendingSort)