Exemplo n.º 1
0
        public async Task <bool> AddQuizPropertiesAsync(BiblePathsCoreDbContext context, string bibleId)
        {
            bool retval = true;

            // If we're using a Template we'll use that name, otherwise well use
            // a Book or Booklist name.
            if (PredefinedQuiz > 0) // Template Scenario
            {
                PredefinedQuiz Template = await context.PredefinedQuizzes.FindAsync(PredefinedQuiz);

                if (Template != null)
                {
                    BookOrTemplateName = Template.QuizName;
                }
                else
                {
                    BookOrTemplateName = "Unknown";
                }
            }
            else
            {
                BookOrTemplateName = await BibleBook.GetBookorBookListNameAsync(context, bibleId, BookNumber);
            }
            QuestionNumber = QuestionsAsked + 1;
            CalculateQuizStats();
            return(retval);
        }
Exemplo n.º 2
0
        public static async Task <BibleBook> GetBookAndChapterByNameAsync(BiblePathsCoreDbContext context, string BibleId, string BookName, int ChapterNum)
        {
            BibleBook PBEBook = new BibleBook();

            try
            {
                PBEBook = await context.BibleBooks.Where(B => B.BibleId == BibleId &&
                                                         B.Name == BookName)
                          .SingleAsync();
            }
            catch
            {
                return(null);
            }

            // TODO: This is not ideal, we should be simply be deleting rather than soft deleting these
            //       So that a simple ANY would work vs. having to retrieve all of these.
            List <QuizBookList> BookLists = await context.QuizBookLists
                                            .Include(L => L.QuizBookListBookMaps)
                                            .Where(L => L.IsDeleted == false)
                                            .ToListAsync();

            await PBEBook.AddPBEBookPropertiesAsync(context, ChapterNum, null, BookLists);

            return(PBEBook);
        }
        // PopulatePBEQuestionAndBookInfoAsync is expensive as it builds a new PBE Book everytime, we don't want to call this often.
        public async Task <bool> PopulatePBEQuestionAndBookInfoAsync(BiblePathsCoreDbContext context)
        {
            // BibleId may not be set on every question, particularly old ones, so default it.
            if (BibleId == null)
            {
                BibleId = Bible.DefaultPBEBibleId;
            }

            BibleBook PBEBook = await BibleBook.GetPBEBookAndChapterAsync(context, BibleId, BookNumber, Chapter);

            if (PBEBook == null)
            {
                return(false);
            }

            if (Chapter == Bible.CommentaryChapter)
            {
                IsCommentaryQuestion = true;
                BookName             = PBEBook.CommentaryTitle;
            }
            else
            {
                IsCommentaryQuestion = false;
                BookName             = PBEBook.Name;
            }
            PBEQuestion = GetPBEQuestionText();

            TimeLimit = (Points * 5) + 20;

            return(true);
        }
Exemplo n.º 4
0
        public async Task <QuizQuestion> GetNextQuizQuestionFromBookAsync(BiblePathsCoreDbContext context, string bibleId, int BookNumber)
        {
            QuizQuestion ReturnQuestion  = new QuizQuestion();
            BibleBook    Book            = new BibleBook();
            int          SelectedChapter = 0;

            try
            {
                Book = await context.BibleBooks.Where(B => B.BibleId == bibleId && B.BookNumber == BookNumber).FirstAsync();
            }
            catch
            {
                // This is the couldn't find the book scenario.
                ReturnQuestion.QuestionSelected = false;
                return(ReturnQuestion);
            }

            // Ok we've got our Book... now which chapter? pick a random one
            Random rand = new Random();

            if (Book.Chapters.HasValue == true)
            {
                SelectedChapter = rand.Next(Book.Chapters.Value) + 1; // Rand will return an int >= 0 and < Book.Chapters, so we add 1 since Chapters are 1 based.
            }
            else
            {
                // Somethings badly wrong with this Book it has not chapters
                ReturnQuestion.QuestionSelected = false;
                return(ReturnQuestion);
            }

            return(await GetNextQuizQuestionFromBookAndChapterAsync(context, bibleId, BookNumber, SelectedChapter));
        }
        public async Task <bool> AddBookNameAsync(BiblePathsCoreDbContext context, string bibleId)
        {
            // Get BookName
            BookName = await BibleBook.GetBookNameAsync(context, bibleId, BookNumber);

            return(true);
        }
Exemplo n.º 6
0
        public async Task <bool> AddBookNameAsync(BiblePathsCoreDbContext context, string bibleId)
        {
            // Get BookName
            BibleBook Book = await context.BibleBooks.Where(B => B.BibleId == bibleId && B.BookNumber == BookNumber).FirstAsync();

            BookName = Book.Name;

            return(true);
        }
Exemplo n.º 7
0
 public MinBook(BibleBook Book)
 {
     BibleId         = Book.BibleId;
     Testament       = Book.Testament;
     TestamentNumber = Book.TestamentNumber;
     BookNumber      = Book.BookNumber;
     Name            = Book.Name;
     Chapters        = Book.Chapters ?? 0;
     HasCommentary   = Book.HasCommentary;
 }
Exemplo n.º 8
0
 public static async Task <string> GetBookorBookListNameAsync(BiblePathsCoreDbContext context, string bibleId, int BookNumber)
 {
     // BookList scenario
     if (BookNumber >= Bible.MinBookListID)
     {
         return((await context.QuizBookLists.Where(L => L.Id == BookNumber).Select(L => new { L.BookListName }).FirstAsync()).BookListName);
     }
     else
     {
         // Get BookName
         return(await BibleBook.GetBookNameAsync(context, bibleId, BookNumber));
     }
 }
Exemplo n.º 9
0
        public static async Task <BibleBook> GetBookByNameAsync(BiblePathsCoreDbContext context, string BibleId, string BookName)
        {
            BibleBook Book = new BibleBook();

            try
            {
                Book = await context.BibleBooks.Include(B => B.BibleChapters)
                       .Where(B => B.BibleId == BibleId &&
                              B.Name == BookName)
                       .SingleAsync();
            }
            catch
            {
                return(null);
            }
            return(Book);
        }
Exemplo n.º 10
0
        public async Task <bool> AddDetailedQuizStatsAsync(BiblePathsCoreDbContext context, string bibleId)
        {
            bool retval = true;

            List <QuizBookStats> bookStats = new List <QuizBookStats>();
            // We need to retrieve all QuizQuestionStat Objects for this Quiz.
            List <QuizQuestionStat> QuestionStats = await context.QuizQuestionStats.Where(S => S.QuizGroupId == Id &&
                                                                                          S.EventType == (int)QuizQuestion.QuestionEventType.QuestionPointsAwarded)
                                                    .ToListAsync();

            // Then we can iterate across each Question.
            foreach (QuizQuestionStat Stat in QuestionStats)
            {
                QuizQuestion Question = await context.QuizQuestions.FindAsync(Stat.QuestionId);

                if (Question == null)
                {
                    // That's problematic and will mess up our stats but nothing we can do about it now.
                }
                else
                {
                    QuizBookStats bookStat = new QuizBookStats();
                    try
                    {
                        bookStat = bookStats.Where(B => B.BookNumber == Question.BookNumber).Single();
                    }
                    catch
                    {
                        // Need to add a new bookStat to this quiz Object.
                        bookStat.BookNumber = Question.BookNumber;
                        bookStat.BookName   = await BibleBook.GetBookNameAsync(context, bibleId, Question.BookNumber);

                        bookStat.ChapterStats = new List <QuizChapterStats>();
                        bookStats.Add(bookStat);
                    }
                    // Now let's go update this bookStat
                    bookStat.AddQuestionToBookStat(Stat, Question);
                }
            }
            BookStats = bookStats;
            return(retval);
        }
Exemplo n.º 11
0
        public void PopulatePBEQuestionInfo(BibleBook PBEBook)
        {
            if (Chapter == Bible.CommentaryChapter)
            {
                IsCommentaryQuestion = true;
                BookName             = PBEBook.CommentaryTitle;
            }
            else
            {
                IsCommentaryQuestion = false;
                BookName             = PBEBook.Name;
            }
            PBEQuestion = GetPBEQuestionText();

            // BibleId may not be set on every question, particularly old ones, so default it.
            if (BibleId == null)
            {
                BibleId = Bible.DefaultPBEBibleId;
            }

            TimeLimit = (Points * 5) + 20;
            LegalNote = GetBibleLegalNote();
        }
Exemplo n.º 12
0
        public async Task <List <MinBook> > GetTemplateBooksAsync(BiblePathsCoreDbContext context, string bibleId)
        {
            List <MinBook> ReturnList = new List <MinBook>();

            if (this.BookNumber < Bible.MinBookListID)
            {
                BibleBook Book = await context.BibleBooks.Where(B => B.BibleId == bibleId &&
                                                                B.BookNumber == this.BookNumber)
                                 .SingleAsync();

                Book.HasCommentary = await Book.HasCommentaryAsync(context);

                MinBook minBook = new MinBook(Book);
                ReturnList.Add(minBook);
            }
            else
            {
                QuizBookList BookList = await context.QuizBookLists.Where(L => L.Id == this.BookNumber &&
                                                                          L.IsDeleted == false)
                                        .Include(L => L.QuizBookListBookMaps)
                                        .SingleAsync();

                foreach (QuizBookListBookMap bookMap in BookList.QuizBookListBookMaps)
                {
                    BibleBook BookMapBook = await context.BibleBooks.Where(B => B.BibleId == bibleId &&
                                                                           B.BookNumber == bookMap.BookNumber)
                                            .SingleAsync();

                    BookMapBook.HasCommentary = await BookMapBook.HasCommentaryAsync(context);

                    MinBook minBook = new MinBook(BookMapBook);
                    ReturnList.Add(minBook);
                }
            }
            return(ReturnList);
        }