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 <ActionResult <IEnumerable <MinQuestion> > > GetQuizQuestions(string BibleId, string BookName, int Chapter) { BibleId = await QuizQuestion.GetValidBibleIdAsync(_context, BibleId); BibleBook Book = await BibleBook.GetBookAndChapterByNameAsync(_context, BibleId, BookName, Chapter); if (Book == null) { return(NotFound()); } List <MinQuestion> minQuestions = new List <MinQuestion>(); List <QuizQuestion> Questions = await _context.QuizQuestions .Include(Q => Q.QuizAnswers) .Where(Q => (Q.BibleId == BibleId || Q.BibleId == null) && Q.BookNumber == Book.BookNumber && Q.Chapter == Chapter && Q.IsDeleted == false && Q.IsAnswered == true).ToListAsync(); foreach (QuizQuestion Question in Questions) { Question.PopulatePBEQuestionInfo(Book); MinQuestion minQuestion = new MinQuestion(Question); minQuestions.Add(minQuestion); } return(minQuestions); }
public async Task <ActionResult <MinQuestion> > PostQuizQuestions([FromBody] MinQuestion Question) { // Confirm we have a valid user and token if (await Question.APIUserTokenCheckAsync(_context) == false) { return(Unauthorized()); } // Now let's create an empty question and put only our valid properties onto it. var emptyQuestion = new QuizQuestion { Created = DateTime.Now, Modified = DateTime.Now, BibleId = Question.BibleId, Points = Question.Points, BookNumber = Question.BookNumber, Chapter = Question.Chapter, StartVerse = Question.StartVerse, EndVerse = Question.EndVerse, Question = Question.Question, Owner = Question.Owner, Source = Question.Source }; _context.QuizQuestions.Add(emptyQuestion); // now we need to add the Answer if there are any foreach (string AnswerString in Question.Answers) { if (AnswerString.Length > 0) { QuizAnswer Answer = new QuizAnswer { Created = DateTime.Now, Modified = DateTime.Now, Question = emptyQuestion, Answer = AnswerString, IsPrimary = true }; _context.QuizAnswers.Add(Answer); // Register that this question has an answer. emptyQuestion.IsAnswered = true; } } await _context.SaveChangesAsync(); MinQuestion returnQuestion = new MinQuestion(emptyQuestion); return(CreatedAtAction("GetQuizQuestion", new { id = returnQuestion.Id }, returnQuestion)); }
public async Task <ActionResult <MinQuestion> > GetQuizQuestion(int id) { var quizQuestion = await _context.QuizQuestions.FindAsync(id); if (quizQuestion == null) { return(NotFound()); } // Explicit load our answers. await _context.Entry(quizQuestion).Collection(q => q.QuizAnswers).LoadAsync(); BibleBook PBEBook = await BibleBook.GetPBEBookAndChapterAsync(_context, quizQuestion.BibleId, quizQuestion.BookNumber, quizQuestion.Chapter); quizQuestion.PopulatePBEQuestionInfo(PBEBook); MinQuestion minQuestion = new MinQuestion(quizQuestion); return(minQuestion); }