Files
secdevops-csharp-app/Components/Pages/Books.razor
Achim H. 251776b9fd
All checks were successful
Tests / Declarative: Post Actions No test results found
csharp-secdevops-pipeline-pod/pipeline/head This commit looks good
Complete Rebuild of Project from HelloWorld to Blazer WebApp
2026-05-12 09:16:44 +02:00

32 lines
892 B
Plaintext

@page "/books"
@using SecDevOpsLab.Models
@using SecDevOpsLab.Data
@inject AppDbContext Db
@rendermode InteractiveServer
<h3>Bücherverwaltung</h3>
<input @bind="newBook.Title" placeholder="Titel" />
<input @bind="newBook.Author" placeholder="Autor" />
<button @onclick="Save">Speichern</button>
<hr />
<ul>
@foreach (var b in bookList) {
<li>@b.Title von @b.Author</li>
}
</ul>
@code {
private Book newBook = new();
private List<Book> bookList = new();
protected override async Task OnInitializedAsync() => bookList = await Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync(Db.Books);
private async Task Save() {
Db.Books.Add(newBook);
await Db.SaveChangesAsync();
newBook = new();
bookList = await Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync(Db.Books);
}
}