private async Task <IList <HintWithState> > GetAllHints(int puzzleID, int teamID) { Hints = await(from Hint hint in _context.Hints join HintStatePerTeam state in _context.HintStatePerTeam on hint.Id equals state.HintID where state.TeamID == teamID && hint.Puzzle.ID == puzzleID orderby hint.DisplayOrder, hint.Description select new HintWithState { Hint = hint, IsUnlocked = state.IsUnlocked }).ToListAsync(); bool solved = await PuzzleStateHelper.IsPuzzleSolved(_context, puzzleID, teamID); if (Hints.Count > 0) { int discount = Hints.Min(hws => (hws.IsUnlocked && hws.Hint.Cost < 0) ? hws.Hint.Cost : 0); // During a beta, once a puzzle is solved, all other hints become free. // There's no IsBeta flag on an event, so check the name. // We can change this in the unlikely event there's a beta-themed hunt. bool allHintsFree = solved && Event.Name.ToLower().Contains("beta"); foreach (HintWithState hint in Hints) { if (allHintsFree) { hint.Discount = -hint.BaseCost; } else if (hint.Hint.Cost < 0) { hint.Discount = discount; } } // if the event is over, show all hints if (Event.AreAnswersAvailableNow && Team.Name.Contains("Archive")) { foreach (HintWithState hint in Hints) { hint.IsUnlocked = true; } } } return(Hints); }