Exemplo n.º 1
0
        public async Task <string> GetQuestionAPITokenAsync(BiblePathsCoreDbContext context)
        {
            string TokenString = "No API Token Found";
            // Find the most recent token for this user
            QuizQuestionStat TokenStat = new QuizQuestionStat();

            try
            {
                TokenStat = await context.QuizQuestionStats.Where(T => T.QuizUserId == this.Id &&
                                                                  T.EventType == (int)QuizQuestion.QuestionEventType.QuestionAPIToken)
                            .OrderByDescending(T => T.EventWritten).Take(1).SingleAsync();
            }
            catch
            {
                // We'll take any exceptions to indicate we couldn't find a Token
                return(TokenString);
            }
            TokenString = "API Token Expired";
            TimeSpan TimeSinceTokenCreated = (TimeSpan)(DateTime.Now - TokenStat.EventWritten);

            if (TimeSinceTokenCreated.TotalHours < 24)
            {
                TokenString = TokenStat.EventData;
            }
            return(TokenString);
        }
Exemplo n.º 2
0
        public async Task <bool> CheckAPITokenAsync(BiblePathsCoreDbContext context, string Token)
        {
            // Find the most recent token for this user
            QuizQuestionStat TokenStat = new QuizQuestionStat();

            try
            {
                TokenStat = await context.QuizQuestionStats.Where(T => T.QuizUserId == this.Id &&
                                                                  T.EventType == (int)QuizQuestion.QuestionEventType.QuestionAPIToken)
                            .OrderByDescending(T => T.EventWritten).Take(1).SingleAsync();
            }
            catch
            {
                // We'll take any exceptions to indicate we couldn't find a Token
                return(false);
            }
            TimeSpan TimeSinceTokenCreated = (TimeSpan)(DateTime.Now - TokenStat.EventWritten);

            if (TimeSinceTokenCreated.TotalHours < 24)
            {
                string TokenString = TokenStat.EventData;
                if (TokenString.Trim() == Token.Trim())
                {
                    // this is the only success case.
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        public void AddQuestionToBookStat(QuizQuestionStat stat, QuizQuestion question)
        {
            QuizChapterStats chapterStat = new QuizChapterStats();

            try
            {
                chapterStat = ChapterStats.Where(C => C.Chapter == question.Chapter).Single();
            }
            catch
            {
                // Need to add a new chapter stat object.
                chapterStat.Chapter = question.Chapter;
                ChapterStats.Add(chapterStat);
            }
            // Now let's go update this chapterStat
            chapterStat.AddQuestionToChapterStat(stat, question);

            // and Finally update thisBookStat.
            QuestionsAsked++;
            if (stat.Points.HasValue)
            {
                PointsAwarded += stat.Points.Value;
            }
            PointsPossible += question.Points;
            if (PointsPossible > 0)
            {
                Percentage = ((float)PointsAwarded / PointsPossible) * 100;
                Percentage = (float)Math.Round((Decimal)Percentage, 2);
            }
            else
            {
                Percentage = 0;
            }
        }
Exemplo n.º 4
0
 public void AddQuestionToChapterStat(QuizQuestionStat stat, QuizQuestion question)
 {
     QuestionsAsked++;
     if (stat.Points.HasValue)
     {
         PointsAwarded += stat.Points.Value;
     }
     PointsPossible += question.Points;
     if (PointsPossible > 0)
     {
         Percentage = ((float)PointsAwarded / PointsPossible) * 100;
         Percentage = (float)Math.Round((Decimal)Percentage, 2);
     }
     else
     {
         Percentage = 0;
     }
 }
        public async Task <bool> RegisterEventAsync(BiblePathsCoreDbContext context, QuestionEventType questionEventType, int QuizUserId, string EventData, int?QuizId, int?Points)
        {
            QuizQuestionStat stat = new QuizQuestionStat
            {
                QuestionId   = Id,
                QuizUserId   = QuizUserId,
                QuizGroupId  = QuizId,
                EventType    = (int)questionEventType,
                EventData    = EventData,
                Points       = Points,
                EventWritten = DateTime.Now
            };

            context.QuizQuestionStats.Add(stat);
            if (await context.SaveChangesAsync() == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }