internal override bool ProcessAnswer(int questId, ref string message) { if (_questIds.Contains(questId)) { _ansIds.Add(questId); } else { return(false); } if (_currentQuestion.QuestIndex != questId) { return(false); } BaseQuestionProvider qp = QuestionsHtmlFactory.GetQuestionProvider(_currentQuestion); string answer = null; bool? isRightAnswer = qp.IsRightAnswer(_requestParams, ref message, ref answer); if (!isRightAnswer.HasValue) { return(false); } double mark = 0; if (isRightAnswer.Value) { mark = _testorData.CoreQuestions.Where(c => c.QuestionId == questId).FirstOrDefault().QuestionMark; _score += mark; } OnScoreChanged(); return(true); }
public QuestAnswerResult ProcessAnswer(int questId, Dictionary <string, List <string> > requestParams) { Debug.Assert(questId > 0); QuestAnswerResult retValue = new QuestAnswerResult(); using (DataClassesTestorCoreDataContext dataContext = new DataClassesTestorCoreDataContext(TestorSecurityProvider.ConnectionString)) { var session = (from c in dataContext.TestSessions join x in dataContext.CoreTests on c.TestId equals x.TestId where c.EndTime == null && c.UserId == Provider.CurrentUser.UserId select new { x.TestId, x.TimeLimit, c.TestSessionId, c.StartTime, c.AdditionalTime }).First(); int timeLimit = session.TimeLimit; if (timeLimit != 0 && session.AdditionalTime.HasValue) { timeLimit += session.AdditionalTime.Value; } if (session.TimeLimit != 0 && (DateTime.Now - session.StartTime).TotalMinutes > timeLimit + 1) { throw new Exception("Время истекло"); } TestorData testorData = GetQuestion(questId, true, false, false); HtmlStore currentQuestion = HtmlStore.GetHtmlStore(testorData, questId); BaseQuestionProvider qp = QuestionsHtmlFactory.GetQuestionProvider(currentQuestion); string message = null; string answer = null; retValue.isRightAnswer = qp.IsRightAnswer(requestParams, ref message, ref answer); retValue.Message = message; retValue.Score = 0; if (!retValue.isRightAnswer.HasValue) { return(retValue); } if (retValue.isRightAnswer.Value) { retValue.Score = testorData.CoreQuestions.Where(c => c.QuestionId == questId).FirstOrDefault().QuestionMark; } var tsq = dataContext.TestSessionQuestions.Where( c => c.QuestionId == questId && c.TestSessionId == session.TestSessionId).First(); tsq.IsRightAnswer = retValue.isRightAnswer; tsq.Answer = answer; dataContext.SubmitChanges(); } return(retValue); }