73 lines
1.8 KiB
Plaintext
73 lines
1.8 KiB
Plaintext
@page "/"
|
|
@using SqliteWasmHelper
|
|
@using Account_SQLite.Data
|
|
@using Microsoft.EntityFrameworkCore
|
|
@inject ISqliteWasmDbContextFactory<AccountContext> Factory
|
|
|
|
<PageTitle>Account_SQLite</PageTitle>
|
|
|
|
<h1>Accounts</h1>
|
|
<p>Type some account:</p>
|
|
<input @bind="newAccount" disabled="@busy" />
|
|
<button @onclick="@(async () => await AddAccountAsync())" disabled="@busy">Add</button>
|
|
|
|
@if (@busy)
|
|
{
|
|
<div class="alert alert-info">💾 Scanning a floppy disk...</div>
|
|
}
|
|
else
|
|
{
|
|
if (accounts.Length < 1)
|
|
{
|
|
<p>I see no-account.</p>
|
|
}
|
|
else
|
|
{
|
|
<ul>
|
|
@foreach (var account in accounts)
|
|
{
|
|
<li>@account.Name</li>
|
|
}
|
|
</ul>
|
|
}
|
|
}
|
|
|
|
Download backup:
|
|
<BackupLink @ref="bl" DbContextType="typeof(AccountContext)" />
|
|
|
|
@code {
|
|
private bool busy;
|
|
private BackupLink bl = null!;
|
|
private string newAccount = string.Empty;
|
|
private Account[] accounts = Array.Empty<Account>();
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await RefreshUiAsync();
|
|
await base.OnInitializedAsync();
|
|
}
|
|
|
|
private async Task RefreshUiAsync()
|
|
{
|
|
using var ctx = await Factory.CreateDbContextAsync();
|
|
busy = true;
|
|
accounts = await ctx.Accounts.ToArrayAsync();
|
|
await bl.RefreshAsync();
|
|
busy = false;
|
|
StateHasChanged();
|
|
}
|
|
|
|
private async Task AddAccountAsync()
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(newAccount))
|
|
{
|
|
using var ctx = await Factory.CreateDbContextAsync();
|
|
ctx.Accounts.Add(new Account { Name = newAccount });
|
|
busy = true;
|
|
await ctx.SaveChangesAsync();
|
|
newAccount = string.Empty;
|
|
busy = false;
|
|
await RefreshUiAsync();
|
|
}
|
|
}
|
|
} |