private void SaveCurrentQuestionInfo(IList<QuestionForExamType> questions) { QuestionForExamType currentQuestion = null; if (SessionCache.BookmarkedExamOngoing) { currentQuestion = GetQuestion(SessionCache.GetBookmarkedCurrentQuestionNo(), SessionCache.CurrentBookmarkedQuestions); } else { currentQuestion = GetQuestion(QuestionNo, questions); } if (currentQuestion == null) { return; } string selectedAnswer = GetSelectedAnswerChoice(); if (selectedAnswer.Length > 0) { ExamSaved questionToSave = userExamManager.GetSavedExamByExamSessionIDAndQuestionID(ExamSessionID, currentQuestion.QuestionID); if (questionToSave == null || questionToSave.Id == 0) { questionToSave = new ExamSaved(); questionToSave.Answer = selectedAnswer; questionToSave.ExamSessionID = ExamSessionID; questionToSave.QuestionID = currentQuestion.QuestionID; DateTime startTime = SessionCache.GetDateTimeInfoForCurrentQuestion(); questionToSave.Time = DateTime.Now.Subtract(startTime).Seconds; questionToSave.TimeStamp = DateTime.Now; questionToSave.UserID = SessionCache.CurrentUser.Author_ID; SessionCache.AnsweredQuestionCount++; } bool finalQuestion = false; if (SessionCache.BookmarkedExamOngoing) { if (SessionCache.CurrentBookmarkedQuestions == null) { finalQuestion = true; } else if (SessionCache.CurrentBookmarkedQuestions.Count == BookmarkedQuestionNo) { finalQuestion = true; } } SaveAnswer(questionToSave,finalQuestion); } else if (chkBookmark.Checked) { if (SessionCache.CurrentBookmarkedQuestions == null) { SessionCache.CurrentBookmarkedQuestions = new List<QuestionForExamType>(); } if (!SessionCache.CurrentBookmarkedQuestions.Contains(currentQuestion)) { SessionCache.CurrentBookmarkedQuestions.Add(currentQuestion); } } }
private void SaveAnswer(ExamSaved questionToSave,bool finalQuestion) { DateTime examStartTime = SessionCache.GetExamStartTime(); currentUserExam.TotalTime = DateTime.Now.Subtract(examStartTime).Seconds; if (finalQuestion) { currentUserExam.EndDate = DateTime.Now; } userExamManager.SaveOrUpdateSavedQuestion(questionToSave, currentUserExam); }