Fehlerbehebung bei leerer DB;
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -9,6 +9,6 @@ namespace MultipleChoiceTrainer.Models
|
||||
public class HomeViewModel
|
||||
{
|
||||
public IList<Category> Categories { get; set; }
|
||||
public int SelectedCategoryId { get; set; }
|
||||
public int? SelectedCategoryId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,15 @@
|
||||
<p class="text-black-50">
|
||||
<a asp-action="edit" asp-controller="Categories" asp-route-id="@category.Id" class="text-black-50"><i class="far fa-edit"></i> Kurs bearbeiten</a>
|
||||
<a asp-action="create" asp-controller="Sections" asp-route-categoryId="@category.Id" class="text-black-50"><i class="far fa-plus"></i> Lektion hinzufügen</a>
|
||||
@if (category.Sections.Any(e => e.Questions.Any())) {
|
||||
<a asp-action="category" asp-controller="Quiz" asp-route-id="@category.Id" class="text-black-50"><i class="far fa-map-marker-question"></i> Quiz starten</a>
|
||||
}
|
||||
</p>
|
||||
|
||||
<div class="list-group">
|
||||
@foreach (var sub in category.Sections)
|
||||
{
|
||||
<ul class="list-group-item list-group-item-action">
|
||||
<div class="list-group-item list-group-item-action">
|
||||
<div class="d-flex w-100 justify-content-between">
|
||||
<h5 class="mb-1">@sub.Name <small class="text-muted">@sub.Description</small></h5>
|
||||
<small><a asp-action="list" asp-controller="questions" asp-route-sectionId="@sub.Id" class="text-decoration-none text-black-50">@sub.Questions.Count() Fragen</a></small>
|
||||
@@ -34,9 +36,12 @@
|
||||
<p class="text-black-50">
|
||||
<a asp-action="edit" asp-controller="Sections" asp-route-id="@sub.Id" class="text-black-50"><i class="far fa-edit"></i> Lektion bearbeiten</a>
|
||||
<a asp-action="create" asp-controller="Questions" asp-route-sectionId="@sub.Id" class="text-black-50"><i class="far fa-plus"></i> Frage hinzufügen</a>
|
||||
@if (sub.Questions.Count > 0)
|
||||
{
|
||||
<a asp-action="section" asp-controller="Quiz" asp-route-id="@sub.Id" class="text-black-50"><i class="far fa-map-marker-question"></i> Quiz starten</a>
|
||||
}
|
||||
</p>
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user