public async Task <IActionResult> OnGetAsync(string BibleId, int QuizId)
        {
            this.BibleId = await Bible.GetValidPBEBibleIdAsync(_context, BibleId);

            // Let's grab the Quiz Object with Stats
            Quiz = await _context.QuizGroupStats.FindAsync(QuizId);

            if (Quiz == null)
            {
                return(RedirectToPage("/error", new { errorMessage = "That's Odd... We were unable to find this Quiz" }));
            }

            // Populate Basic Quiz Info
            _ = await Quiz.AddQuizPropertiesAsync(_context, BibleId);

            _ = await Quiz.AddDetailedQuizStatsAsync(_context, BibleId);

            return(Page());
        }
Esempio n. 2
0
        public async Task <IActionResult> OnGetAsync(string BibleId, int QuizId, string Message)
        {
            IdentityUser user = await _userManager.GetUserAsync(User);

            PBEUser = await QuizUser.GetOrAddPBEUserAsync(_context, user.Email); // Static method not requiring an instance

            if (!PBEUser.IsValidPBEQuizHost())
            {
                return(RedirectToPage("/error", new { errorMessage = "Sorry! You do not have sufficient rights to host a PBE Quiz" }));
            }
            this.BibleId = await Bible.GetValidPBEBibleIdAsync(_context, BibleId);

            // Let's grab the Quiz Object
            Quiz = await _context.QuizGroupStats.FindAsync(QuizId);

            if (Quiz == null)
            {
                return(RedirectToPage("/error", new { errorMessage = "That's Odd... We were unable to find this Quiz" }));
            }
            if (Quiz.QuizUser != PBEUser)
            {
                return(RedirectToPage("/error", new { errorMessage = "Sorry! Only a Quiz Owner can run a Quiz" }));
            }
            _ = await Quiz.AddQuizPropertiesAsync(_context, BibleId);

            // Now for the Question Object... we're going to take 3 swings at this for the scenario where we don't have enough questions.
            int iterations = 0;

            do
            {
                Question = await Quiz.GetNextQuizQuestionAsync(_context, BibleId);

                iterations++;
            }while (iterations < 3 && Question.QuestionSelected == false);

            // This is the no questions found scenario
            if (Question.QuestionSelected == false)
            {
                return(RedirectToPage("/error", new { errorMessage = "Sorry! We failed to find a random question after three tries... please add more questions." }));
            }

            if (Question.BibleId == null)
            {
                Question.BibleId = BibleId;
            }

            BibleBook PBEBook = await BibleBook.GetPBEBookAndChapterAsync(_context, 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, true);

            Question.LegalNote = Question.GetBibleLegalNote();

            // Build our Select List and set a default points value of -1 to require selection.
            ViewData["PointsSelectList"] = Question.GetQuestionPointsSelectList();
            Question.PointsAwarded       = -1;

            UserMessage = GetUserMessage(Message);
            return(Page());
        }