public async Task <IActionResult> OnGetAsync(int?id, string BibleId, int?BookNumber, int?Chapter, int?Verse) { bool hasValidStepId = false; Step = new PathNode(); int StepBookNumber = 0; int StepChapter = 0; // TODO: How does this work with Form Post and Get scenarios? if (this.BibleId != null) { BibleId = this.BibleId; } BibleId = await Step.GetValidBibleIdAsync(_context, BibleId); this.BibleId = BibleId; // There are three distinct scenarios to account for here: // 1. Step Scenario, we have an id of a step but no BookNumber or Chapter, this is the most basic step scenario. // 2. Context Scenario, we have an id of a step and a BookNumber and Chapter, user is navigating for context. // 3. Study Scenario, we have no id of a step, but have Booknumber and Chapter, user is reading the Bible. if (id != null) { Step = await _context.PathNodes.FindAsync(id); if (Step == null) { return(RedirectToPage("/error", new { errorMessage = "That's Odd! We weren't able to find this Step" })); } _ = await Step.AddPathStepPropertiesAsync(_context); Scenario = StepScenarios.Step; hasValidStepId = true; StepBookNumber = Step.BookNumber; StepChapter = Step.Chapter; } if (BookNumber.HasValue && Chapter.HasValue) { Step.BookNumber = (int)BookNumber; Step.Chapter = (int)Chapter; if (Verse.HasValue) { Step.StartVerse = (int)Verse; Step.EndVerse = (int)Verse; } if (await Step.ValidateBookChapterAsync(_context, this.BibleId) == false) { return(RedirectToPage("/error", new { errorMessage = "That's Odd! We weren't able to find this Step, or Book/Chapter combination" })); } else { if (hasValidStepId) { if (Step.BookNumber == StepBookNumber && Step.Chapter == StepChapter) { Scenario = StepScenarios.Step; // we're back to our step. } else { Scenario = StepScenarios.Context; } } else { Scenario = StepScenarios.Study; } } } _ = await Step.AddGenericStepPropertiesAsync(_context, BibleId); Step.Verses = await Step.GetBibleVersesAsync(_context, BibleId, false, true); if (Scenario == StepScenarios.Study) { PageTitle = Step.BookName + " " + Step.Chapter; // Add related path info foreach (BibleVerse verse in Step.Verses) { _ = await verse.GetRelatedPathsAsync(_context); } } else { PageTitle = Step.PathName; } // Let's see if we need to register any events for this step read. if (Scenario == StepScenarios.Step) { _ = await Step.RegisterReadEventsAsync(_context); } BibleSelectList = await GetBibleSelectListAsync(BibleId); return(Page()); }
public async Task <IActionResult> OnGetAsync(int GroupId, int TeamId, int StepId) { Group = await _context.GameGroups.FindAsync(GroupId); if (Group == null) { return(RedirectToPage("/error", new { errorMessage = "That's Odd! We weren't able to find that Group" })); } Team = await _context.GameTeams.FindAsync(TeamId); if (Team == null) { return(RedirectToPage("/error", new { errorMessage = "That's Odd! We were not able to find that Team" })); } if (Team.GroupId != Group.Id) { return(RedirectToPage("/error", new { errorMessage = "That's Odd! The Team and Group do not match" })); } string BibleId = await GameTeam.GetValidBibleIdAsync(_context, null); // Now let's check that StepId if (StepId == Team.CurrentStepId) { PathNode CurrentStep = await _context.PathNodes.FindAsync(Team.CurrentStepId); if (CurrentStep == null) { return(RedirectToPage("/error", new { errorMessage = "That's Very Odd! We couldn't find Current Step" })); } _ = await CurrentStep.AddGenericStepPropertiesAsync(_context, BibleId); _ = await CurrentStep.AddPathStepPropertiesAsync(_context); // We have a winner! Let's update the Team Object _context.Attach(Team); Team.Modified = DateTime.Now; if (CurrentStep.FWStepId > 0) { Team.CurrentStepId = CurrentStep.FWStepId; Team.StepNumber = Team.StepNumber + 1; Team.BoardState = (int)GameTeam.GameBoardState.WordSelect; } else { Team.BoardState = (int)GameTeam.GameBoardState.Completed; } await _context.SaveChangesAsync(); // We need to add the Quotes around the TeamID, then signal the StateChange string GroupName = "\"" + Team.Id.ToString() + "\""; await _hubContext.Clients.Group(GroupName).SendAsync("StateChange"); return(RedirectToPage("Team", new { GroupId = Team.GroupId, TeamId = Team.Id, Message = "Good Job! You're on the right Path" })); } else { _context.Attach(Team); Team.Modified = DateTime.Now; Team.BoardState = (int)GameTeam.GameBoardState.WordSelectOffPath; await _context.SaveChangesAsync(); // We need to add the Quotes around the TeamID, then signal the StateChange string GroupName = "\"" + Team.Id.ToString() + "\""; await _hubContext.Clients.Group(GroupName).SendAsync("StateChange"); return(RedirectToPage("Team", new { GroupId = Team.GroupId, TeamId = Team.Id, Message = "Uh Oh! You've drifted off Path" })); } }