diff --git a/MultipleChoiceTrainer/Controllers/HomeController.cs b/MultipleChoiceTrainer/Controllers/HomeController.cs index df4ccde..fb989ab 100644 --- a/MultipleChoiceTrainer/Controllers/HomeController.cs +++ b/MultipleChoiceTrainer/Controllers/HomeController.cs @@ -30,7 +30,7 @@ namespace MultipleChoiceTrainer.Controllers if (signInManager.IsSignedIn(User)) { var categories = context.Categories.Include(e => e.Sections).ThenInclude(e => e.Questions).ToList(); - var selectedCategory = categoryId.HasValue ? categoryId.Value : categories.First().Id; + var selectedCategory = categoryId ?? (categories.FirstOrDefault()?.Id); return View(new HomeViewModel() { Categories = categories, SelectedCategoryId = selectedCategory }); } return View(); diff --git a/MultipleChoiceTrainer/Models/HomeViewModel.cs b/MultipleChoiceTrainer/Models/HomeViewModel.cs index 543b464..36f2562 100644 --- a/MultipleChoiceTrainer/Models/HomeViewModel.cs +++ b/MultipleChoiceTrainer/Models/HomeViewModel.cs @@ -9,6 +9,6 @@ namespace MultipleChoiceTrainer.Models public class HomeViewModel { public IList Categories { get; set; } - public int SelectedCategoryId { get; set; } + public int? SelectedCategoryId { get; set; } } } diff --git a/MultipleChoiceTrainer/Views/Home/_homeLogInPartial.cshtml b/MultipleChoiceTrainer/Views/Home/_homeLogInPartial.cshtml index f3bfae6..7b216ef 100644 --- a/MultipleChoiceTrainer/Views/Home/_homeLogInPartial.cshtml +++ b/MultipleChoiceTrainer/Views/Home/_homeLogInPartial.cshtml @@ -20,13 +20,15 @@

Kurs bearbeiten     Lektion hinzufügen     - Quiz starten + @if (category.Sections.Any(e => e.Questions.Any())) { + Quiz starten + }

@foreach (var sub in category.Sections) { - +
}