public async Task <ActionResult <MinQuestion> > GetFitBQuestion(string BibleId, string BookName, int Chapter, int Verse) { BibleId = await QuizQuestion.GetValidBibleIdAsync(_context, BibleId); BibleBook Book = await BibleBook.GetBookAndChapterByNameAsync(_context, BibleId, BookName, Chapter); if (Book == null) { return(NotFound()); } BibleVerse verse = new BibleVerse(); try { verse = await _context.BibleVerses.Where(v => v.BibleId == BibleId && v.BookNumber == Book.BookNumber && v.Chapter == Chapter && v.Verse == Verse) .SingleAsync(); } catch { return(NotFound()); } QuizQuestion Question = new QuizQuestion(); Question = await Question.BuildQuestionForVerseAsync(_context, verse, 8, BibleId); Question.PopulatePBEQuestionInfo(Book); MinQuestion minQuestion = new MinQuestion(Question); return(minQuestion); }
public async Task <IActionResult> OnGetAsync(string BibleId, int BookNumber, int Chapter, int?VerseNum, bool?BuildQuestion) { IdentityUser user = await _userManager.GetUserAsync(User); PBEUser = await QuizUser.GetOrAddPBEUserAsync(_context, user.Email); // Static method not requiring an instance if (!PBEUser.IsValidPBEQuestionBuilder()) { return(RedirectToPage("/error", new { errorMessage = "Sorry! You do not have sufficient rights to add a PBE question" })); } bool generateQuestion = false; if (BuildQuestion.HasValue) { generateQuestion = (bool)BuildQuestion; } Question = new QuizQuestion(); // Setup our PBEBook Object Question.BibleId = await QuizQuestion.GetValidBibleIdAsync(_context, BibleId); if (generateQuestion) { BibleVerse verse = await BibleVerse.GetVerseAsync(_context, Question.BibleId, BookNumber, Chapter, (int)VerseNum); Question = await Question.BuildQuestionForVerseAsync(_context, verse, 10, Question.BibleId); foreach (QuizAnswer Answer in Question.QuizAnswers) { AnswerText += Answer.Answer; } } else { Question.BookNumber = BookNumber; Question.Chapter = Chapter; Question.StartVerse = VerseNum ?? 1; // set to 1 if VersNum is Null. Question.EndVerse = VerseNum ?? 1; // set to 1 if VersNum is Null. Question.Points = 0; } BibleBook PBEBook = await BibleBook.GetPBEBookAndChapterAsync(_context, Question.BibleId, Question.BookNumber, Question.Chapter); if (PBEBook == null) { return(RedirectToPage("/error", new { errorMessage = "That's Odd! We weren't able to find the PBE Book." })); } Question.PopulatePBEQuestionInfo(PBEBook); Question.Verses = await Question.GetBibleVersesAsync(_context, false); IsCommentary = (Question.Chapter == Bible.CommentaryChapter); if (IsCommentary == false) { ChapterQuestionCount = PBEBook.BibleChapters.Where(c => c.ChapterNumber == Question.Chapter).First().QuestionCount; } CommentaryQuestionCount = PBEBook.CommentaryQuestionCount; // and now we need a Verse Select List ViewData["VerseSelectList"] = new SelectList(Question.Verses, "Verse", "Verse"); ViewData["PointsSelectList"] = Question.GetPointsSelectList(); return(Page()); }