public async Task <CumulativeQuizViewModel> SaveCumulativeResponse(CumulativeQuizViewModel quizVM, int responseId) { if (await _context.ModuleHistories.AnyAsync(mh => mh.ModuleId == quizVM.CumulativeQuizId && mh.IsPassed)) { return(null); } if (await _context.CumulativeResponses.AnyAsync(r => r.CumulativeQuizId == quizVM.CumulativeQuizId && r.StudentId == quizVM.Student.Id && r.QuestionId == quizVM.Question.Id)) { return(await _quizManager.GetCumulativeQnA(quizVM.CumulativeQuizId)); } CumulativeRespons response = new CumulativeRespons() { AnswerId = responseId, CumulativeQuizId = quizVM.CumulativeQuizId, QuestionId = quizVM.Question.Id, StudentId = quizVM.Student.Id, LectureId = quizVM.Question.LectureId }; _context.CumulativeResponses.Add(response); await _context.SaveChangesAsync(); return(await _quizManager.GetCumulativeQnA(quizVM.CumulativeQuizId)); }
public async Task <ActionResult> CumulativeQuiz(int cumulativeQuizId) { if (!Context.CumulativeQuizPasseds.Any(itp => itp.Id == cumulativeQuizId && itp.IsPassed == false)) { return(RedirectToAction("Index", "Student")); } CumulativeQuizViewModel model = await _quizManager.GetCumulativeQnA(cumulativeQuizId); var toSetStartDate = Context.CumulativeQuizPasseds.SingleOrDefault(iq => iq.Id == cumulativeQuizId && iq.IsPassed == false && iq.StartDate == null); if (toSetStartDate != null) { toSetStartDate.StartDate = DateTime.UtcNow; await Context.SaveChangesAsync(); } _timerAssociates.StartTimer(cumulativeQuizId, TimeSpan.FromMilliseconds(model.TimeLeft), TimerAssociates.TimerType.Cumulative); return(View(model)); }