public async Task <ActionResult> DropQuiz(string courseId, Guid slideId, bool isLti) { var slide = courseManager.GetCourse(courseId).GetSlideById(slideId); if (slide is QuizSlide) { var userId = User.Identity.GetUserId(); if (userQuizzesRepo.GetQuizDropStates(courseId, userId, slideId).Count(b => b) < GetMaxDropCount(slide as QuizSlide) && !userQuizzesRepo.IsQuizScoredMaximum(courseId, userId, slideId)) { await userQuizzesRepo.DropQuiz(userId, slideId); await slideCheckingsRepo.RemoveAttempts(courseId, slideId, userId); await visitsRepo.UpdateScoreForVisit(courseId, slideId, userId); if (isLti) { LtiUtils.SubmitScore(slide, userId); } } } var model = new { courseId, slideId = slide.Id, isLti }; if (isLti) { return(RedirectToAction("LtiSlide", "Course", model)); } return(RedirectToAction("SlideById", "Course", model)); }
public async Task <ActionResult> DropQuiz(string courseId, string slideId, bool isLti) { var slide = courseManager.GetCourse(courseId).GetSlideById(slideId); if (slide is QuizSlide) { var userId = User.Identity.GetUserId(); if (userQuizzesRepo.GetQuizDropStates(courseId, userId, slideId).Count(b => b) < GetMaxDropCount(slide as QuizSlide) && !userQuizzesRepo.GetQuizBlocksTruth(courseId, userId, slideId).All(b => b.Value)) { await userQuizzesRepo.DropQuiz(userId, slideId); await visitsRepo.DropAttempt(slideId, userId); if (isLti) { LtiUtils.SubmitScore(slide, userId); } } } var model = new { courseId, slideIndex = slide.Index, isLti }; if (isLti) { return(RedirectToAction("LtiSlide", "Course", model)); } return(RedirectToAction("Slide", "Course", model)); }
public ActionResult Quiz(QuizSlide slide, string courseId, string userId, bool isGuest, bool isLti = false, ManualQuizChecking manualQuizCheckQueueItem = null, int?send = null) { metricSender.SendCount("quiz.show"); if (isLti) { metricSender.SendCount("quiz.show.lti"); } metricSender.SendCount($"quiz.show.{courseId}"); metricSender.SendCount($"quiz.show.{courseId}.{slide.Id}"); var course = courseManager.FindCourse(courseId); if (course == null) { return(HttpNotFound()); } if (isGuest) { metricSender.SendCount("quiz.show.to.guest"); return(PartialView(GuestQuiz(course, slide))); } var slideId = slide.Id; var maxTriesCount = GetMaxTriesCount(courseId, slide); var state = GetQuizState(courseId, userId, slideId); var quizState = state.Item1; var tryNumber = state.Item2; var resultsForQuizes = GetResultForQuizes(courseId, userId, slideId, state.Item1); log.Info($"Создаю тест для пользователя {userId} в слайде {courseId}:{slide.Id}, isLti = {isLti}"); var quizVersion = quizzesRepo.GetLastQuizVersion(courseId, slideId); if (quizState != QuizState.NotPassed) { quizVersion = userQuizzesRepo.FindQuizVersionFromUsersAnswer(courseId, slideId, userId); } /* If we haven't quiz version in database, create it */ if (quizVersion == null) { quizVersion = quizzesRepo.AddQuizVersionIfNeeded(courseId, slide); } /* Restore quiz slide from version stored in the database */ var quiz = quizVersion.GetRestoredQuiz(course, course.FindUnitBySlideId(slide.Id)); slide = new QuizSlide(slide.Info, quiz); if (quizState == QuizState.Subtotal) { var score = resultsForQuizes?.AsEnumerable().Sum(res => res.Value) ?? 0; /* QuizState.Subtotal is partially obsolete. If user fully solved quiz, then show answers. Else show empty quiz for the new try... */ if (score == quiz.MaxScore) { quizState = QuizState.Total; } /* ... and show last try's answers only if argument `send` has been passed in query */ else if (!send.HasValue) { quizState = QuizState.NotPassed; /* ... if we will show answers from last try then drop quiz */ userQuizzesRepo.DropQuiz(courseId, userId, slideId); } } var userAnswers = userQuizzesRepo.GetAnswersForShowOnSlide(courseId, slide, userId); var canUserFillQuiz = CanUserFillQuiz(quizState); var questionAnswersFrequency = new DefaultDictionary <string, DefaultDictionary <string, int> >(); if (User.HasAccessFor(courseId, CourseRole.CourseAdmin)) { questionAnswersFrequency = quiz.Blocks.OfType <ChoiceBlock>().ToDictionary( block => block.Id, block => userQuizzesRepo.GetAnswersFrequencyForChoiceBlock(courseId, slide.Id, block.Id).ToDefaultDictionary() ).ToDefaultDictionary(); } var model = new QuizModel { Course = course, Slide = slide, QuizState = quizState, TryNumber = tryNumber, MaxTriesCount = maxTriesCount, ResultsForQuizes = resultsForQuizes, AnswersToQuizes = userAnswers, IsLti = isLti, ManualQuizCheckQueueItem = manualQuizCheckQueueItem, CanUserFillQuiz = canUserFillQuiz, GroupsIds = Request.GetMultipleValuesFromQueryString("group"), QuestionAnswersFrequency = questionAnswersFrequency, }; return(PartialView(model)); }