Exemplo n.º 1
0
        public async Task <RealTimeStatisticsViewModel> GetRealTimeStatisticsViewModel(Lector lector)
        {
            var realTimeStatistics =
                await(
                    from mh in _context.ModuleHistories
                    where mh.StartTime != null && mh.IsPassed == false && mh.LectorId == lector.Id
                    join lh in _context.LecturesHistories on mh.LectureHistoryId equals lh.Id
                    join m in _context.Modules on mh.ModuleId equals m.Id
                    join q in _context.Questions on m.Id equals q.ModuleId into qjoin
                    join sd in _context.StudentDisciplines on lh.DisciplineId equals sd.DisciplineId into sdjoin
                    select new RealTimeStatisticsViewModel
            {
                LecturesHistory = lh,
                Module          = m,
                ModuleHistory   = mh,
                Questions       = qjoin,
                StudentIds      = sdjoin.Select(s => s.StudentId)
            }).SingleOrDefaultAsync();

            var timer = TimerAssociates.GetTimer(realTimeStatistics.ModuleHistory.Id, TimerAssociates.TimerType.Realtime) ??
                        _timerAssociates.StartTimer(realTimeStatistics.ModuleHistory.Id,
                                                    TimeSpan.FromMinutes(realTimeStatistics.Module.MinutesToPass), TimerAssociates.TimerType.Realtime);

            realTimeStatistics.Lector     = lector;
            realTimeStatistics.TimeFinish = timer.ModuleFinish.ToLocalTime().ToString("yyyy-MM-ddTHH:mm:ss");
            realTimeStatistics.Groups     =
                await(from g in _context.Groups
                      join lhg in _context.LectureHistoryGroups on g.Id equals lhg.GroupId
                      where lhg.LectureHistoryId == realTimeStatistics.LecturesHistory.Id
                      select g).ToListAsync();

            return(realTimeStatistics);
        }
Exemplo n.º 2
0
        public async Task <ActionResult> IndividualQuiz(int individualQuizId)
        {
            if (!Context.IndividualQuizPasseds.Any(itp => itp.Id == individualQuizId && itp.IsPassed == false))
            {
                return(RedirectToAction("Index", "Student"));
            }
            var model = await _quizManager.GetIndividualQnA(individualQuizId);

            var toSetStartDate = Context.IndividualQuizPasseds.SingleOrDefault(iq =>
                                                                               iq.Id == individualQuizId && iq.IsPassed == false && iq.StartDate == null);

            if (toSetStartDate != null)
            {
                toSetStartDate.StartDate = DateTime.UtcNow;
                await Context.SaveChangesAsync();
            }
            _timerAssociates.StartTimer(individualQuizId, TimeSpan.FromMilliseconds(model.TimeLeft), TimerAssociates.TimerType.Individual);
            return(View(model));
        }
Exemplo n.º 3
0
        public async Task StartModule(int moduleHistoryId)
        {
            ModuleHistory moduleHistory =
                await _db.ModuleHistories.SingleOrDefaultAsync(mh => mh.Id == moduleHistoryId);

            if (moduleHistory.IsPassed)
            {
                var responsesToDelete =
                    from r in _db.RealtimeResponses
                    where r.LectureHistoryId == moduleHistory.LectureHistoryId
                    join q in _db.Questions on r.QuestionId equals q.Id
                    where q.ModuleId == moduleHistory.ModuleId
                    select r;
                _db.RealtimeResponses.RemoveRange(responsesToDelete);
                moduleHistory.IsPassed = false;
            }
            moduleHistory.StartTime = DateTime.UtcNow;
            TimeSpan minutesToPass = TimeSpan.FromMinutes(await _db.Modules.Where(m => m.Id == moduleHistory.ModuleId)
                                                          .Select(m => m.MinutesToPass).SingleOrDefaultAsync());

            _timerAssociates.StartTimer(moduleHistoryId, minutesToPass, TimerAssociates.TimerType.Realtime);
            await _db.SaveChangesAsync();
        }