예제 #1
0
        public async Task <RealTimeQuizViewModel> SaveResponse(RealTimeQuizViewModel quizVM, int responseId)
        {
            if (await _context.ModuleHistories.AnyAsync(mh => mh.ModuleId == quizVM.ModuleHistoryId && mh.IsPassed))
            {
                return(null);
            }
            if (await _context.RealtimeResponses.AnyAsync(r =>
                                                          r.ModuleHistoryId == quizVM.ModuleHistoryId && r.StudentId == quizVM.Student.Id &&
                                                          r.QuestionId == quizVM.Question.Id))
            {
                return(await _quizManager.UpdateQuizModel(quizVM));
            }
            RealtimeRespons response = new RealtimeRespons
            {
                AnswerId         = responseId,
                LectureHistoryId = quizVM.LectureHistoryId,
                ModuleHistoryId  = quizVM.ModuleHistoryId,
                QuestionId       = quizVM.Question.Id,
                StudentId        = quizVM.Student.Id,
                GroupId          = quizVM.Student.GroupId
            };

            _context.RealtimeResponses.Add(response);
            await _context.SaveChangesAsync();

            Clients.All.ResponseRecieved();
            return(await _quizManager.UpdateQuizModel(quizVM));
        }
예제 #2
0
        public async Task ResovlePassedRealtimeQuiz(int moduleId, int studentId, int moduleHistoryId, int lectureId)
        {
            _context.RealtimeModulesPasseds.Add(new RealtimeModulesPassed()
            {
                ModuleId        = moduleId,
                StudentId       = studentId,
                ModuleHistoryId = moduleHistoryId
            });
            var passedModules =
                await(from m in _context.Modules
                      where m.LectureId == lectureId
                      join rtmp in _context.RealtimeModulesPasseds on m.Id equals rtmp.ModuleId into groupjoin
                      from gj in groupjoin.DefaultIfEmpty()
                      where gj == null || gj.StudentId == studentId
                      select gj).ToListAsync();

            if (passedModules.All(a => a != null))
            {
                if (await _context.IndividualQuizPasseds.AnyAsync(iqp => iqp.LectureId == lectureId && iqp.StudentId == studentId))
                {
                    return;
                }
                IndividualQuizPassed individualTestsPassed = new IndividualQuizPassed()
                {
                    DisciplineId = _context.Lectures.Where(w => w.Id == lectureId).Select(s => s.DisciplineId)
                                   .SingleOrDefault(),
                    IsPassed  = false,
                    LectureId = lectureId,
                    StudentId = studentId
                };
                _context.IndividualQuizPasseds.Add(individualTestsPassed);
            }


            await _context.SaveChangesAsync();
        }
예제 #3
0
        public async Task StartLecture(ReasignViewModel model)
        {
            var disc   = model.Disciplines[0].Id;
            var lect   = model.Lectures[0].Id;
            var date   = DateTime.UtcNow;
            var lector = await AccountCredentials.GetLector();

            var lectureHistory = _db.LecturesHistories.Add(new LecturesHistory
            {
                LectureId    = lect,
                DisciplineId = disc,
                StartTime    = date,
                IsFrozen     = false,
                LectorId     = lector.Id
            });
            await _db.SaveChangesAsync();

            _db.ModuleHistories.AddRange(
                from m in await _db.Modules.ToListAsync()
                where m.LectureId == lect
                select new ModuleHistory
            {
                IsPassed         = false,
                LectureHistoryId = lectureHistory.Id,
                ModuleId         = m.Id,
                StartTime        = null,
                LectorId         = lector.Id
            });

            _db.LectureHistoryGroups.AddRange(
                from g in model.Groups
                where g.IsSelected
                select new LectureHistoryGroup
            {
                GroupId          = g.Id,
                LectureHistoryId = lectureHistory.Id
            });

            await _db.SaveChangesAsync();
        }