public async Task <IActionResult> OnGetAsync(string eventId, int puzzleId) { Event currentEvent = await EventHelper.GetEventFromEventId(_context, eventId); if (currentEvent == null) { return(Unauthorized()); } EventId = currentEvent.ID; PuzzleUser user = LoggedInUser; if (user == null) { return(Unauthorized()); } Team team = await UserEventHelper.GetTeamForPlayer(_context, currentEvent, user); if (team == null) { return(Unauthorized()); } Puzzle kitchenSyncPuzzle = await _context.Puzzles.FirstOrDefaultAsync(m => m.Name == "Kitchen Sync" && m.Event.ID == EventId); KitchenSyncId = kitchenSyncPuzzle.ID; Puzzle heatSyncPuzzle = await _context.Puzzles.FirstOrDefaultAsync(m => m.Name == "Heat Sync" && m.Event.ID == EventId); HeatSyncId = heatSyncPuzzle.ID; Puzzle lipSyncPuzzle = await _context.Puzzles.FirstOrDefaultAsync(m => m.Name == "Lip Sync" && m.Event.ID == EventId); LipSyncId = lipSyncPuzzle.ID; Puzzle syncTestMetapuzzle = await _context.Puzzles.FirstOrDefaultAsync(m => m.Name == "Sync Test" && m.Event.ID == EventId); MetapuzzleId = syncTestMetapuzzle.ID; var helper = new SyncHelper(_context); List <int> query_puzzle_ids = new List <int> { KitchenSyncId, HeatSyncId, LipSyncId }; var response = await helper.GetSyncResponse(currentEvent.ID, team.ID, puzzleId, query_puzzle_ids, 0, null, null); var responseSerialized = JsonConvert.SerializeObject(response); InitialSyncString = HttpUtility.JavaScriptStringEncode(responseSerialized); return(Page()); }
public async Task <IActionResult> OnGetAsync(string eventId, int puzzleId) { Event currentEvent = await EventHelper.GetEventFromEventId(_context, eventId); if (currentEvent == null) { return(Unauthorized()); } EventId = currentEvent.ID; PuzzleUser user = LoggedInUser; if (user == null) { return(Unauthorized()); } Team team = await UserEventHelper.GetTeamForPlayer(_context, currentEvent, user); if (team == null) { return(Unauthorized()); } Puzzle thisPuzzle = await _context.Puzzles.FirstOrDefaultAsync(m => m.ID == puzzleId && m.Event.ID == EventId); if (thisPuzzle == null || !thisPuzzle.Name.Equals("The Play That Goes Wrong")) { return(Unauthorized()); } MetapuzzleId = puzzleId; var helper = new SyncHelper(_context); List <int> query_puzzle_ids = Enumerable.Range(MetapuzzleId - 10, 11).ToList(); var response = await helper.GetSyncResponse(currentEvent.ID, team.ID, puzzleId, query_puzzle_ids, 0, null, null); var responseSerialized = JsonConvert.SerializeObject(response); InitialSyncString = HttpUtility.JavaScriptStringEncode(responseSerialized); return(Page()); }