public ChoiceBlockAnswerInfo GetChoiseBlockAnswerInfo(string courseId, string slideId, ChoiceBlock block, string userId, int questionIndex) { var ans = new SortedDictionary<string, bool>(); foreach (var item in block.Items) { ans[item.Id] = false; } var isRight = false; foreach (var quizItem in db.UserQuizzes.Where(q => q.UserId == userId && q.SlideId == slideId && q.QuizId == block.Id && q.ItemId != null && !q.isDropped)) { isRight = quizItem.IsRightQuizBlock; ans[quizItem.ItemId] = true; } return new ChoiceBlockAnswerInfo { AnswersId = ans, Id = questionIndex.ToString(), RealyRightAnswer = new HashSet<string>(block.Items.Where(x => x.IsCorrect).Select(x => x.Id)), IsRight = isRight }; }
private IEnumerable<QuizInfoForDb> CreateQuizInfoForDb(ChoiceBlock choiceBlock, IGrouping<string, QuizAnswer> answers) { if (!choiceBlock.Multiple) { var answerItemId = answers.First().ItemId; var isTrue = choiceBlock.Items.First(x => x.Id == answerItemId).IsCorrect; return new List<QuizInfoForDb> { new QuizInfoForDb { QuizId = choiceBlock.Id, ItemId = answerItemId, IsRightAnswer = isTrue, Text = null, QuizType = typeof (ChoiceBlock), IsRightQuizBlock = isTrue } }; } var ans = answers.Select(x => x.ItemId).ToList() .Select(x => new QuizInfoForDb { QuizId = choiceBlock.Id, IsRightAnswer = choiceBlock.Items.Where(y => y.IsCorrect).Any(y => y.Id == x), ItemId = x, Text = null, QuizType = typeof(ChoiceBlock), IsRightQuizBlock = false }).ToList(); var isRightQuizBlock = ans.All(x => x.IsRightAnswer) && choiceBlock.Items.Where(x => x.IsCorrect) .Select(x => x.Id) .All(x => ans.Where(y => y.IsRightAnswer).Select(y => y.ItemId).Contains(x)); foreach (var info in ans) info.IsRightQuizBlock = isRightQuizBlock; return ans; }
public static System.Web.WebPages.HelperResult QuizBlock(ChoiceBlock block, BlockRenderContext context) { return new System.Web.WebPages.HelperResult(__razor_helper_writer => { var items = block.ShuffledItems(); var isMultiply = block.Multiple; var typeInp = isMultiply ? "checkbox" : "radio"; QuizBlockData model = context.GetBlockData(block) ?? new QuizBlockData(new QuizModel(), 1, QuizState.NotPassed); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t<div class=\"quiz-block-mark "); WebViewPage.WriteTo(@__razor_helper_writer, typeInp); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\" id=\'"); WebViewPage.WriteTo(@__razor_helper_writer, block.Id + "_quizBlock"); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\'>\r\n"); for (var itemIndex = 0; itemIndex < items.Length; itemIndex++) { var item = items[itemIndex]; var id = isMultiply ? itemIndex + "noMult" : model.BlockIndex.ToString(); var itemChecked = model.QuizState != QuizState.NotPassed && model.QuizModel.AnswersToQuizes[block.Id].Contains(item.Id); var ans = itemChecked ? "checked" : ""; var itemClass = ""; var title = ""; if (model.QuizState == QuizState.Total) { itemClass = item.IsCorrect ? "right-quiz" : itemChecked ? "wrong-quiz" : ""; title = (item.IsCorrect ? "Правильный" : "Неправильный") + " вариант"; } WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t<div class=\"quiz\">\r\n\t\t\t\t<label class=\""); WebViewPage.WriteTo(@__razor_helper_writer, itemClass); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\" title=\""); WebViewPage.WriteTo(@__razor_helper_writer, title); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\">\r\n\t\t\t\t\t<input "); WebViewPage.WriteTo(@__razor_helper_writer, ans); WebViewPage.WriteLiteralTo(@__razor_helper_writer, " autocomplete=\"off\" id=\'"); WebViewPage.WriteTo(@__razor_helper_writer, block.Id + "quizBlock" + item.Id); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\' name="); WebViewPage.WriteTo(@__razor_helper_writer, "group" + id); WebViewPage.WriteLiteralTo(@__razor_helper_writer, " type=\""); WebViewPage.WriteTo(@__razor_helper_writer, typeInp); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\">\r\n\t\t\t\t\t"); WebViewPage.WriteTo(@__razor_helper_writer, item.Description.RenderTex()); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\r\n\t\t\t\t</label>\r\n"); if (model.QuizState == QuizState.Total && item.IsCorrect) { WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t\t<i class=\"glyphicon glyphicon-ok\" style=\"color: green\" title=\""); WebViewPage.WriteTo(@__razor_helper_writer, title); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\"></i>\r\n"); } if (model.QuizState == QuizState.Total && !string.IsNullOrEmpty(item.Explanation)) { WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t\t<p class=\"text-muted\">"); WebViewPage.WriteTo(@__razor_helper_writer, item.Explanation); WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</p>\r\n"); } WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t</div>\r\n"); } WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t</div>\r\n"); }); }
private static QuizAnswerInfo GetChoiceBlockAnswerInfo(IReadOnlyDictionary<string, List<UserQuiz>> answers, ChoiceBlock block, int questionIndex) { IEnumerable<UserQuiz> answer = new List<UserQuiz>(); if (answers.ContainsKey(block.Id)) answer = answers[block.Id].Where(q => q.ItemId != null); var ans = new SortedDictionary<string, bool>(); foreach (var item in block.Items) { ans[item.Id] = false; } var isRight = false; foreach (var quizItem in answer.Where(quizItem => ans.ContainsKey(quizItem.ItemId))) { isRight = quizItem.IsRightQuizBlock; ans[quizItem.ItemId] = true; } return new ChoiceBlockAnswerInfo { AnswersId = ans, Id = questionIndex.ToString(), RealyRightAnswer = new HashSet<string>(block.Items.Where(x => x.IsCorrect).Select(x => x.Id)), IsRight = isRight }; }