Complete Rebuild of Project from HelloWorld to Blazer WebApp
This commit is contained in:
31
Components/Pages/Books.razor
Normal file
31
Components/Pages/Books.razor
Normal file
@@ -0,0 +1,31 @@
|
||||
@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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user