示例#1
0
        public async Task ResovlePassedIndividualQuiz(int individualQuizId)
        {
            var toUpdate = await _context.IndividualQuizPasseds.SingleOrDefaultAsync(w => w.Id == individualQuizId);

            if (toUpdate == null)
            {
                return;
            }
            toUpdate.IsPassed = true;
            toUpdate.EndDate  = DateTime.UtcNow;
            _timerAssociates.DisposeTimer(individualQuizId, TimerAssociates.TimerType.Individual);
            if (_context.IndividualQuizPasseds.Any(it => it.DisciplineId == toUpdate.DisciplineId && it.IsPassed && it.StudentId == toUpdate.StudentId))
            {
                var passedLectures =
                    await(from l in _context.Lectures
                          where l.DisciplineId == toUpdate.DisciplineId
                          join iqp in _context.IndividualQuizPasseds on l.Id equals iqp.LectureId into groupjoin
                          from gj in groupjoin.DefaultIfEmpty()
                          where gj == null || gj.StudentId == toUpdate.StudentId
                          select gj).ToListAsync();

                if (passedLectures.All(a => a != null))
                {
                    CumulativeQuizPassed cumulativeTestsPassed = new CumulativeQuizPassed()
                    {
                        DisciplineId = toUpdate.DisciplineId,
                        IsPassed     = false,
                        StudentId    = toUpdate.StudentId
                    };
                    var returnvalue = _context.CumulativeQuizPasseds.Add(cumulativeTestsPassed);
                    IEnumerable <CumulativeQuizLecture> cumulativeLectures =
                        from pl in passedLectures
                        where pl != null
                        select new CumulativeQuizLecture()
                    {
                        CumulativeQuizId = returnvalue.Id,
                        LectureId        = pl.LectureId
                    };
                    _context.CumulativeQuizLectures.AddRange(cumulativeLectures);
                }
            }
            await _context.SaveChangesAsync();
        }
示例#2
0
        public async Task ModulePassed(int moduleHistoryId)
        {
            ModuleHistory moduleHistory =
                await _db.ModuleHistories.SingleOrDefaultAsync(mh => mh.Id == moduleHistoryId);

            moduleHistory.IsPassed = true;
            await _db.SaveChangesAsync();

            var lectureId =
                await(from l in _db.Lectures
                      join lh in _db.LecturesHistories on l.Id equals lh.LectureId
                      where lh.Id == moduleHistory.LectureHistoryId
                      select l).Select(l => l.Id).SingleOrDefaultAsync();

            foreach (var studentId in QuizHub.Students.GetStudents(moduleHistoryId))
            {
                await _quizManager.ResovlePassedRealtimeQuiz(moduleHistory.ModuleId, studentId, moduleHistoryId, lectureId);
            }
            _timerAssociates.DisposeTimer(moduleHistoryId, TimerAssociates.TimerType.Realtime);
        }