public async Task <CumulativeQuizViewModel> GetCumulativeQnA(int cumulativeQuizId) { Student student = await AccountCredentials.GetStudent(); var question = await(from q in _context.Questions where !_context.CumulativeResponses.Any(cr => cr.Id == cumulativeQuizId && cr.QuestionId == q.Id) // && q.QuestionType == QuestionType.IndividualId group q by q.Id into groupjoin from gj in groupjoin join cql in _context.CumulativeQuizLectures on gj.LectureId equals cql.LectureId where cql.CumulativeQuizId == cumulativeQuizId && _context.CumulativeResponses.Count(cr => cr.CumulativeQuizId == cql.CumulativeQuizId && cql.LectureId == gj.LectureId) <= Math.Floor((double)(groupjoin.Count(c => c.LectureId == cql.LectureId) / groupjoin.Count() * 20)) select gj).OrderBy(q => Guid.NewGuid()).FirstOrDefaultAsync(); if (question == null) { await ResovlePassedCumulativeQuiz(cumulativeQuizId); return(null); } return(new CumulativeQuizViewModel { Question = question, Student = student, Answers = await GetAnswersList(question.Id), CumulativeQuizId = cumulativeQuizId, TimeLeft = _timerAssociates.TimeLeft(cumulativeQuizId, TimerAssociates.TimerType.Cumulative) }); }
public async Task <IndividualQuizViewModel> GetIndividualQnA(int individualQuizId) { Student student = await AccountCredentials.GetStudent(); var question = await(from q in _context.Questions where !_context.IndividualResponses.Any(ir => ir.IndividualQuizId == individualQuizId && ir.QuestionId == q.Id) // && q.QuestionType == QuestionType.IndividualId join it in _context.IndividualQuizPasseds on q.LectureId equals it.LectureId where it.Id == individualQuizId select q).OrderBy(q => Guid.NewGuid()).FirstOrDefaultAsync(); if (question == null) { await ResovlePassedIndividualQuiz(individualQuizId); return(null); } return(new IndividualQuizViewModel { Question = question, Student = student, Answers = await GetAnswersList(question.Id), IndividualQuizId = individualQuizId, TimeLeft = _timerAssociates.TimeLeft(individualQuizId, TimerAssociates.TimerType.Individual) }); }
public async Task <RealTimeQuizViewModel> GetRealtimeQnA(int moduleHistoryId) { var student = await AccountCredentials.GetStudent(); bool studentCanPass = await _studentPageHelper.StudentCanPass(moduleHistoryId, student.Id); if (studentCanPass) { RealTimeQuizViewModel qnA = new RealTimeQuizViewModel(); if (await _context.RealtimeModulesPasseds.AnyAsync(smp => smp.StudentId == student.Id && smp.ModuleHistoryId == moduleHistoryId)) { return(qnA); } ModuleHistory moduleHistory = await _context.ModuleHistories.SingleOrDefaultAsync(mh => mh.Id == moduleHistoryId); int lectureId = _context.LecturesHistories.Where(lh => lh.Id == moduleHistory.LectureHistoryId) .Select(lh => lh.LectureId).SingleOrDefault(); var question = await _context.Questions.Where(q => q.ModuleId == moduleHistory.ModuleId && q.QuestionType == QuestionType.RealtimeId && !_context.RealtimeResponses.Where(r => r.ModuleHistoryId == moduleHistoryId && r.StudentId == student.Id).Select(r => r.QuestionId).Contains(q.Id)) .OrderBy(q => Guid.NewGuid()).FirstOrDefaultAsync(); if (question == null) { await ResovlePassedRealtimeQuiz(moduleHistory.ModuleId, student.Id, moduleHistoryId, lectureId); return(qnA); } qnA = new RealTimeQuizViewModel { Question = question, Student = student, Answers = await GetAnswersList(question.Id), LectureHistoryId = moduleHistory.LectureHistoryId, ModuleHistoryId = moduleHistoryId }; return(qnA); } return(null); }