Quiz funktional;
This commit is contained in:
@@ -78,7 +78,28 @@ namespace MultipleChoiceTrainer.Controllers
|
|||||||
|
|
||||||
if (string.IsNullOrEmpty(viewModel.CurrentQuestion.Text))
|
if (string.IsNullOrEmpty(viewModel.CurrentQuestion.Text))
|
||||||
{
|
{
|
||||||
|
var refQuestion = _context.Questions.Include(e => e.Choices).First(q => q.Id == viewModel.CurrentQuestion.Id);
|
||||||
|
newViewModel.Evaluations = new List<Evaluation>();
|
||||||
|
newViewModel.PreviousQuestion = refQuestion.Text;
|
||||||
|
foreach(var answer in viewModel.Choices)
|
||||||
|
{
|
||||||
|
var refChoice = refQuestion.Choices.First(rc => rc.Id == answer.Id);
|
||||||
|
newViewModel.Evaluations.Add(new Evaluation()
|
||||||
|
{
|
||||||
|
Text = refChoice.Text,
|
||||||
|
GivenAnswer = answer.IsTrue,
|
||||||
|
RightAnswer = refChoice.IsTrue,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var dbAnswer = new Answer()
|
||||||
|
{
|
||||||
|
Date = DateTime.Now,
|
||||||
|
QuestionId = viewModel.CurrentQuestion.Id,
|
||||||
|
Successfull = newViewModel.PassedPreviousQuestion
|
||||||
|
};
|
||||||
|
refQuestion.Answers.Add(dbAnswer);
|
||||||
|
_context.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
GetQuestion(newViewModel);
|
GetQuestion(newViewModel);
|
||||||
|
|||||||
@@ -10,13 +10,36 @@
|
|||||||
|
|
||||||
<input asp-for="CurrentQuestion.Id" type="hidden" />
|
<input asp-for="CurrentQuestion.Id" type="hidden" />
|
||||||
|
|
||||||
|
@if (Model.HasPreviousResult)
|
||||||
|
{
|
||||||
|
<div class="alert alert-@(Model.PassedPreviousQuestion ? "success" : "danger" )" role="alert">
|
||||||
|
<h4 class="alert-heading">@(Model.PassedPreviousQuestion ? "Gut gemacht!" : "Leider falsch!" )</h4>
|
||||||
|
<p class="lead">@Model.PreviousQuestion</p>
|
||||||
|
<table class="table table-borderless table-striped table-sm table-dark border border-dark">
|
||||||
|
<tr>
|
||||||
|
<th>Frage</th>
|
||||||
|
<th>Soll</th>
|
||||||
|
<th>Ist</th>
|
||||||
|
</tr>
|
||||||
|
@foreach (var eval in Model.Evaluations)
|
||||||
|
{
|
||||||
|
<tr class="table-@(eval.Success ? "success" : "danger")">
|
||||||
|
<td>@eval.Text</td>
|
||||||
|
<td><i class="fa fa-@(eval.RightAnswer ? "check" : "times")"></i></td>
|
||||||
|
<td><i class="fa fa-@(eval.GivenAnswer ? "check" : "times")"></i></td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
<h4>Frage beantworten</h4>
|
<h4>Frage beantworten</h4>
|
||||||
<p class="text-black-50">aus Lektion <i>@Model.CurrentQuestion.Section.Name</i>, Kurs <i>@Model.CurrentQuestion.Section.Category.Name</i></p>
|
<p class="text-black-50">aus Lektion <i>@Model.CurrentQuestion.Section.Name</i>, Kurs <i>@Model.CurrentQuestion.Section.Category.Name</i></p>
|
||||||
<hr />
|
<hr />
|
||||||
<p class="lead">
|
<p class="lead">
|
||||||
@Model.CurrentQuestion.Text <small class="text-black-50"> <i class="fas fa-info-circle" data-toggle="tooltip" title="(@Model.CurrentQuestion.Choices.Count(e => e.IsTrue) von @Model.Choices.Count())"></i></small>
|
@Model.CurrentQuestion.Text <small class="text-black-50"> <i class="fas fa-info-circle" data-toggle="tooltip" title="(@Model.CurrentQuestion.Choices.Count(e => e.IsTrue) von @Model.Choices.Count())"></i></small>
|
||||||
</p>
|
</p>
|
||||||
@for(int i = 0; i < Model.Choices.Count(); i++)
|
@for (int i = 0; i < Model.Choices.Count(); i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
|
|||||||
Reference in New Issue
Block a user