/// <summary> /// for getting continuous learning attempts /// </summary> /// <param name="userId"></param> /// <param name="attempt"></param> /// <param name="quizDetails"></param> /// <returns></returns> public List <QuizAttempts> GetContinuousLearningQuizAttempts(string userId, int attempt, QuizDetails quizDetails) { var userFilter = Builders <BsonDocument> .Filter.Eq("userid", userId); var latestAttempt = _continuousLearningAdapter.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(_continuousLearningAttemptsCollection, 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(_continuousLearningAttemptsCollection, userAndAttempt); } } } var continuousLearningQuizzes = _continuousLearningAdapter.GetContinuousLearningAssessmentQuizzes(); 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); item.TryGetValue("yes", out BsonValue yesValue); item.TryGetValue("somewhat", out BsonValue somewhatValue); item.TryGetValue("no", out BsonValue noValue); var answer = Common.BooleanNullCheck(yesValue) ? "Yes" : Common.BooleanNullCheck(somewhatValue) ? "Somewhat" : "No"; var question = continuousLearningQuizzes.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 = answer, userId = Common.StringNullCheck(useridValue), attempt = Common.IntegerNullCheck(attemptValue), type = quizDetails.type }); } return(quizAttempts); }
public int InsertContinuousLearningQuizResponse(List <ContinuousLearningAssessmentQuizAttempts> continuousLearningAssessmentQuizAttempts) { var latestDetails = _continuousLearningAdapter.GetLatestId(); var latestId = 0; var attemptId = _continuousLearningAdapter.GetLatestAttemptByUser(continuousLearningAssessmentQuizAttempts[0].userid); if (latestDetails != null) { latestId = latestDetails.id; } foreach (var item in continuousLearningAssessmentQuizAttempts) { latestId++; item.id = latestId; item.attemptcount = (attemptId?.attemptcount ?? 0) + 1; item.attempttimestamp = DateTime.Now.ToString(CultureInfo.InvariantCulture); } return(_continuousLearningAdapter.InsertContinuousLearningAssessmentQuizResponse(continuousLearningAssessmentQuizAttempts)); }