Antworten werden geshufflet; Fragen kommen ausgeglichen dran;
This commit is contained in:
@@ -42,7 +42,8 @@ namespace MultipleChoiceTrainer.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
public async Task<IActionResult> Create(QuestionViewModel question)
|
public async Task<IActionResult> Create(QuestionViewModel question)
|
||||||
{
|
{
|
||||||
|
question.CreationDate = DateTime.Now;
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
question.Choices = question.Choices.ToList().Where(e => !string.IsNullOrEmpty(e.Text) && !string.IsNullOrWhiteSpace(e.Text)).ToList();
|
question.Choices = question.Choices.ToList().Where(e => !string.IsNullOrEmpty(e.Text) && !string.IsNullOrWhiteSpace(e.Text)).ToList();
|
||||||
|
|||||||
@@ -60,13 +60,16 @@ namespace MultipleChoiceTrainer.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
questions = questions.ToList().AsQueryable();
|
questions = questions.ToList().AsQueryable();
|
||||||
questions = questions.OrderByDescending(e => e.Answers.Count());
|
var newestDate = questions.Select(e => e.CreationDate).Max();
|
||||||
|
questions = questions.OrderByDescending(e => e.Answers.Where(a => a.Date > newestDate).Count());
|
||||||
|
var minAnswerCount = questions.Select(e => e.Answers.Where(a => a.Date > newestDate).Count()).Min();
|
||||||
|
questions = questions.Where(e => e.Answers.Where(a => a.Date > newestDate).Count() == minAnswerCount);
|
||||||
questions = questions.Take(10);
|
questions = questions.Take(10);
|
||||||
|
|
||||||
|
|
||||||
vm.CurrentQuestion = questions.ElementAt(_rnd.Next(0, questions.Count()-1));
|
vm.CurrentQuestion = questions.ElementAt(_rnd.Next(0, questions.Count()-1));
|
||||||
|
|
||||||
vm.Choices = vm.CurrentQuestion.Choices.Select(oc => new Choice() { Id = oc.Id, Text = oc.Text }).ToList();
|
vm.Choices = vm.CurrentQuestion.Choices.Select(oc => new Choice() { Id = oc.Id, Text = oc.Text }).OrderBy(a => Guid.NewGuid()).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Quiz(QuizViewModel viewModel)
|
public IActionResult Quiz(QuizViewModel viewModel)
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ namespace MultipleChoiceTrainer.Models.DataModels
|
|||||||
[NotNullOrEmpty]
|
[NotNullOrEmpty]
|
||||||
public string Text { get; set; }
|
public string Text { get; set; }
|
||||||
|
|
||||||
|
public DateTime CreationDate { get; set; }
|
||||||
|
|
||||||
public Section Section { get; set; }
|
public Section Section { get; set; }
|
||||||
public int SectionId { get; set; }
|
public int SectionId { get; set; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user