Beispiel #1
0
		private static QuizAnswerInfo GetMatchingBlockAnswerInfo(IReadOnlyDictionary<string, List<UserQuiz>> answers, MatchingBlock block, int questionIndex)
		{
			IEnumerable<UserQuiz> userAnswers = new List<UserQuiz>();
			UserQuiz firstAnswer = null;
			if (answers.ContainsKey(block.Id))
			{
				userAnswers = answers[block.Id].Where(q => q.ItemId != null);
				firstAnswer = userAnswers.FirstOrDefault();
			}

			var isRightMatches = new List<bool>();
			foreach (var match in block.Matches)
			{
				var userAnswer = userAnswers.FirstOrDefault(a => a.ItemId == match.GetHashForFixedItem());
				isRightMatches.Add(userAnswer != null && userAnswer.IsRightAnswer);
			}

			return new MatchingBlockAnswerInfo
			{
				Id = questionIndex.ToString(),
				IsRightMatches = isRightMatches,
				Score = firstAnswer?.QuizBlockScore ?? 0,
				MaxScore = firstAnswer?.QuizBlockMaxScore ?? 0,
			};
		}
public static System.Web.WebPages.HelperResult QuizBlock(MatchingBlock block, BlockRenderContext context)
{
return new System.Web.WebPages.HelperResult(__razor_helper_writer => {


 
	var fixedItems = block.GetMatches(block.ShuffleFixed);
	var movableItems = block.GetMatches(true);

	QuizBlockData model = context.GetBlockData(block) ?? new QuizBlockData(new QuizModel(), 1, QuizState.NotPassed);
	if (model.QuizState != QuizState.NotPassed && model.QuizModel.AnswersToQuizes[block.Id].FirstOrDefault() != null)
	{
		var userAnswers = model.QuizModel.AnswersToQuizes[block.Id];
		fixedItems = block.GetMatches().OrderBy(item => userAnswers.FindIndex(answer => item.GetHashForFixedItem() == answer.ItemId)).ToList();
		movableItems = GetMovableItemsAccordingToUserAnswers(userAnswers, fixedItems);
	}

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t<div class=\"quiz-block-matching ");


WebViewPage.WriteTo(@__razor_helper_writer, context.CanUserFillQuiz ? "" : "not-movable");

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\" id=\'");


                                            WebViewPage.WriteTo(@__razor_helper_writer, block.Id + "_quizBlock");

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\'>\r\n");


 		if (model.QuizState == QuizState.NotPassed)
		{

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t<div class=\"quiz-block-matching__description text-muted\">Перетащите элементы и" +
"з правого столбца на свободные места</div>\r\n");


		}


 		if (model.QuizState == QuizState.Total)
		{

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t<div class=\"quiz-block-matching__correct-description row\">\r\n\t\t\t\t<div class=\"te" +
"xt-muted col-sm-3 col-sm-offset-3\">Ваш вариант</div>\r\n");


 				if (model.ShowCorrectAnswer)
				{

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t\t<div class=\"text-success col-sm-3 col-sm-offset-1\">Правильный вариант</div>\r" +
"\n");


				}

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t</div>\r\n");


		}

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t<ul>\r\n");


 			for (var itemIndex = 0; itemIndex < fixedItems.Count; itemIndex++)
			{
				var fixedItem = fixedItems[itemIndex];
				var movableItem = movableItems[itemIndex];
				var isRightClass = "";
				if (model.QuizState == QuizState.Total && model.ShowCorrectAnswer)
				{
					isRightClass = fixedItem.Id == movableItem.Id ? "right" : "wrong";
				}

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t<li>\r\n\t\t\t\t\t<div class=\"quiz quiz-block-matching__item ");


     WebViewPage.WriteTo(@__razor_helper_writer, isRightClass);

WebViewPage.WriteLiteralTo(@__razor_helper_writer, " row\">\r\n\t\t\t\t\t\t<input autocomplete=\"off\" id=\'");


WebViewPage.WriteTo(@__razor_helper_writer, block.Id + "quizBlock" + fixedItem.GetHashForFixedItem());

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\' type=\"hidden\">\r\n\t\t\t\t\t\t<div class=\"quiz-block-matching__fixed-item col-xs-3\" dat" +
"a-item-id=\"");


                               WebViewPage.WriteTo(@__razor_helper_writer, fixedItem.GetHashForFixedItem());

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\">");


                                                                 WebViewPage.WriteTo(@__razor_helper_writer, fixedItem.FixedItem.RenderTex());

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</div>\r\n");


 						if (model.QuizState == QuizState.NotPassed)
						{

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t\t\t\t<div class=\"quiz-block-matching__droppable col-xs-3\" data-block-id=\"");


                                WebViewPage.WriteTo(@__razor_helper_writer, block.Id);

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\" data-item-id=\"");


                                                         WebViewPage.WriteTo(@__razor_helper_writer, fixedItem.GetHashForFixedItem());

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\"></div>\r\n");



WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t\t\t\t<div class=\"quiz-block-matching__source__droppable col-xs-3 col-sm-offset-" +
"1 added\" data-block-id=\"");


                                                              WebViewPage.WriteTo(@__razor_helper_writer, block.Id);

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\" data-movable-item-id=\"");


                                                                                               WebViewPage.WriteTo(@__razor_helper_writer, movableItem.GetHashForMovableItem());

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\">\r\n\t\t\t\t\t\t\t\t<div class=\"quiz-block-matching__movable-item\" data-block-id=\"");


                           WebViewPage.WriteTo(@__razor_helper_writer, block.Id);

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\" data-item-id=\"");


                                                    WebViewPage.WriteTo(@__razor_helper_writer, movableItem.GetHashForMovableItem());

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\">");


                                                                                          WebViewPage.WriteTo(@__razor_helper_writer, movableItem.MovableItem.RenderTex());

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</div>\r\n\t\t\t\t\t\t\t</div>\r\n");


						}
						else
						{

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t\t\t\t<div class=\"quiz-block-matching__droppable col-xs-3 added\" data-block-id=\"" +
"");


                                      WebViewPage.WriteTo(@__razor_helper_writer, block.Id);

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\" data-item-id=\"");


                                                               WebViewPage.WriteTo(@__razor_helper_writer, fixedItem.GetHashForFixedItem());

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\" data-movable-item-id=\"");


                                                                                                                       WebViewPage.WriteTo(@__razor_helper_writer, movableItem.GetHashForMovableItem());

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\">\r\n\t\t\t\t\t\t\t\t<div class=\"quiz-block-matching__movable-item\" data-block-id=\"");


                           WebViewPage.WriteTo(@__razor_helper_writer, block.Id);

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\" data-item-id=\"");


                                                    WebViewPage.WriteTo(@__razor_helper_writer, movableItem.GetHashForMovableItem());

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\">");


                                                                                          WebViewPage.WriteTo(@__razor_helper_writer, movableItem.MovableItem.RenderTex());

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</div>\r\n\t\t\t\t\t\t\t</div>\r\n");


							if (model.QuizState == QuizState.Total && model.ShowCorrectAnswer)
							{

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t\t\t\t\t<div class=\"quiz-block-matching__fixed-item correct col-xs-3 col-sm-offse" +
"t-1\">\r\n\t\t\t\t\t\t\t\t\t");


WebViewPage.WriteTo(@__razor_helper_writer, fixedItem.MovableItem.RenderTex());

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\r\n\t\t\t\t\t\t\t\t</div>\r\n");


							}
							if (context.CanUserFillQuiz)
							{

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t\t\t\t\t<div class=\"quiz-block-matching__source__droppable col-xs-3 col-sm-offset" +
"-1\" data-block-id=\"");


                                                         WebViewPage.WriteTo(@__razor_helper_writer, block.Id);

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\">\r\n\t\t\t\t\t\t\t\t</div>\r\n");


							}
						}

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t\t\t\t\t\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</li>\r\n");


			}

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t</ul>\r\n\t</div>\r\n");


	if (model.QuizState == QuizState.Total && !string.IsNullOrEmpty(block.Explanation))
	{

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "\t\t<div class=\"text-muted\">");


WebViewPage.WriteTo(@__razor_helper_writer, block.Explanation);

WebViewPage.WriteLiteralTo(@__razor_helper_writer, "</div>\r\n");


	}

});

}
Beispiel #3
0
		private IEnumerable<QuizInfoForDb> CreateQuizInfoForDb(MatchingBlock matchingBlock, IGrouping<string, QuizAnswer> answers)
		{
			var ans = answers.ToList()
				.Select(x => new QuizInfoForDb
				{
					QuizId = matchingBlock.Id,
					IsRightAnswer = matchingBlock.Matches.FirstOrDefault(m => m.GetHashForFixedItem() == x.ItemId)?.
										GetHashForMovableItem() == x.Text,
					ItemId = x.ItemId,
					Text = x.Text,
					QuizType = typeof(MatchingBlock),
					QuizBlockScore = 0,
					QuizBlockMaxScore = matchingBlock.MaxScore
				}).ToList();

			var isRightQuizBlock = ans.All(x => x.IsRightAnswer);
			var blockScore = isRightQuizBlock ? matchingBlock.MaxScore : 0;
			foreach (var info in ans)
				info.QuizBlockScore = blockScore;

			return ans;
		}