Implement backup and restore functionality; add IBackupService and BackupService; refactor services to use DbContextFactory
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
<button class="btn btn-secondary btn-nav" @onclick="NavigateBack">
|
||||
<i class="bi bi-arrow-left"></i> Zurück
|
||||
</button>
|
||||
|
|
||||
<button class="btn btn-success btn-nav" @onclick="() => showAddEntry = true">
|
||||
<i class="bi bi-plus-lg"></i> Buchung
|
||||
</button>
|
||||
@@ -37,6 +38,7 @@
|
||||
<button class="btn btn-dark btn-nav" @onclick="HandleExport">
|
||||
<i class="bi bi-file-earmark-pdf"></i> PDF
|
||||
</button>
|
||||
|
|
||||
<button class="btn btn-nav @(showCurrentYearOnly ? "btn-primary" : "btn-outline-secondary")" @onclick="ToggleYearFilter">
|
||||
<i class="bi bi-funnel"></i> @(showCurrentYearOnly ? $"Nur {DateTime.Now.Year}" : "Alle Buchungen")
|
||||
</button>
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
@page "/"
|
||||
@inject IAccountService AccountService
|
||||
@inject IBackupService BackupService
|
||||
@inject ISettingsService SettingsService
|
||||
@inject IJSRuntime JsRuntime
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
<div class="container-fluid">
|
||||
|
||||
@@ -19,8 +22,22 @@
|
||||
<button class="btn-nav btn-primary" @onclick="() => showAddAccount = true">
|
||||
<i class="bi bi-plus-lg"></i> Neues Konto
|
||||
</button>
|
||||
|
|
||||
<button class="btn-nav btn-success" @onclick="HandleBackupAsync">
|
||||
<i class="bi bi-save"></i> Backup
|
||||
</button>
|
||||
<button class="btn-nav btn-warning" @onclick="HandleRestoreAsync">
|
||||
<i class="bi bi-arrow-counterclockwise"></i> Restore
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrWhiteSpace(operationMessage))
|
||||
{
|
||||
<div class="alert @operationMessageClass mb-3" role="alert">
|
||||
@operationMessage
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (accounts == null)
|
||||
{
|
||||
<div class="text-center py-5">
|
||||
@@ -56,6 +73,8 @@
|
||||
private bool showAddAccount;
|
||||
private bool showEditClubName;
|
||||
private string clubName = string.Empty;
|
||||
private string? operationMessage;
|
||||
private string operationMessageClass = "alert-info";
|
||||
private string DisplayClubName => string.IsNullOrWhiteSpace(clubName) ? "Mein Verein" : clubName;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
@@ -87,4 +106,39 @@
|
||||
showEditClubName = false;
|
||||
await LoadClubName();
|
||||
}
|
||||
|
||||
private async Task HandleBackupAsync()
|
||||
{
|
||||
var message = await BackupService.CreateBackupAsync();
|
||||
if(message.Contains("fehlgeschlagen", StringComparison.OrdinalIgnoreCase)) {
|
||||
SetOperationMessage(message, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async Task HandleRestoreAsync()
|
||||
{
|
||||
var confirmed = await JsRuntime.InvokeAsync<bool>("confirm",
|
||||
"Restore überschreibt die aktuelle Datenbank. Möchten Sie fortfahren?");
|
||||
|
||||
if (!confirmed) return;
|
||||
|
||||
var message = await BackupService.RestoreBackupAsync();
|
||||
var isSuccess = message.StartsWith("Wiederherstellung erfolgreich", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
if (isSuccess)
|
||||
{
|
||||
// Reload the Blazor app so all components/services re-query from restored DB.
|
||||
NavigationManager.NavigateTo("/", forceLoad: true);
|
||||
} else {
|
||||
SetOperationMessage(message, isSuccess);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void SetOperationMessage(string message, bool success)
|
||||
{
|
||||
operationMessage = message;
|
||||
operationMessageClass = success ? "alert-success" : "alert-danger";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user