45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using cfs_tracker.Data;
|
|
|
|
namespace cfs_tracker.ViewModels;
|
|
|
|
public partial class OptionsViewModel : ObservableObject
|
|
{
|
|
private readonly HealthEntryRepository _repository;
|
|
|
|
[ObservableProperty]
|
|
private string deleteConfirmationText = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private string statusText = string.Empty;
|
|
|
|
public IAsyncRelayCommand DeleteAllDataCommand { get; }
|
|
|
|
public OptionsViewModel(HealthEntryRepository repository)
|
|
{
|
|
_repository = repository;
|
|
DeleteAllDataCommand = new AsyncRelayCommand(DeleteAllDataAsync, CanDeleteAllData);
|
|
}
|
|
|
|
partial void OnDeleteConfirmationTextChanged(string value)
|
|
{
|
|
DeleteAllDataCommand.NotifyCanExecuteChanged();
|
|
}
|
|
|
|
private bool CanDeleteAllData()
|
|
{
|
|
return string.Equals(
|
|
DeleteConfirmationText?.Trim(),
|
|
"löschen",
|
|
StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
private async Task DeleteAllDataAsync()
|
|
{
|
|
await _repository.DeleteAllAsync();
|
|
|
|
DeleteConfirmationText = string.Empty;
|
|
StatusText = "Alle gespeicherten Einträge wurden gelöscht.";
|
|
}
|
|
} |