/// <summary>
        /// For getting making time for me Quiz details
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="attempt"></param>
        /// <param name="quizDetails"></param>
        /// <returns></returns>
        public List <QuizAttempts> GetMakingTimeForMeQuizAttempts(string userId, int attempt, QuizDetails quizDetails)
        {
            var userFilter = Builders <BsonDocument> .Filter.Eq("userid", userId);

            var latestAttempt          = _makingTimeForMeQuizAdapter.GetLatestAttemptByUser(userId);
            List <BsonDocument> result = new List <BsonDocument>();

            if (latestAttempt != null)
            {
                if (attempt == 1)
                {
                    var attemptFilter = Builders <BsonDocument> .Filter.Eq("attemptcount", latestAttempt.attemptcount);

                    var userAndAttempt = Builders <BsonDocument> .Filter.And(userFilter, attemptFilter);

                    result = _quizAttempt.GetRecords(_makingTimeForMeAttemptsCollection, userAndAttempt);
                }
                else
                {
                    if (latestAttempt.attemptcount > 1)
                    {
                        var attemptFilter = Builders <BsonDocument> .Filter.Eq("attemptcount", latestAttempt.attemptcount - 1);

                        var userAndAttempt = Builders <BsonDocument> .Filter.And(userFilter, attemptFilter);

                        result = _quizAttempt.GetRecords(_makingTimeForMeAttemptsCollection, userAndAttempt);
                    }
                }
            }
            var maingTimeForMeQuizzes = _makingTimeForMeQuizAdapter.GetMakingTimeForMeQuizzes();

            List <QuizAttempts> quizAttempts = new List <QuizAttempts>();

            foreach (var item in result)
            {
                item.TryGetValue("answer", out BsonValue answerValue);
                item.TryGetValue("userid", out BsonValue useridValue);
                item.TryGetValue("attemptcount", out BsonValue attemptValue);
                item.TryGetValue("questionid", out BsonValue questionidValue);

                var question = maingTimeForMeQuizzes.Where(a => a.id == Common.IntegerNullCheck(questionidValue));
                quizAttempts.Add(new QuizAttempts
                {
                    question = question.Count() == 0 ? "" : question.Select(a => a.question).FirstOrDefault().ToString(CultureInfo.InvariantCulture),
                    answer   = Common.StringNullCheck(answerValue),
                    userId   = Common.StringNullCheck(useridValue),
                    attempt  = Common.IntegerNullCheck(attemptValue),
                    type     = quizDetails.type
                });
            }

            return(quizAttempts);
        }
Пример #2
0
 public List <MakingTimeForMeQuiz> GetMakingTimeForMeQuizzes()
 {
     return(_makingTimeForMeQuizAdapter.GetMakingTimeForMeQuizzes());
 }