Confirm Delete
This commit is contained in:
@@ -1,16 +1,10 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Jugenddienst_Stunden.Models;
|
||||
using Jugenddienst_Stunden.Types;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Jugenddienst_Stunden.ViewModels;
|
||||
namespace Jugenddienst_Stunden.ViewModels;
|
||||
internal class StundeViewModel : ObservableObject, IQueryAttributable {
|
||||
|
||||
public int id { get; set; }
|
||||
@@ -24,6 +18,7 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
|
||||
|
||||
public event EventHandler<string> AlertEvent;
|
||||
public event EventHandler<string> InfoEvent;
|
||||
public event Func<string, string, Task<bool>> ConfirmEvent;
|
||||
|
||||
|
||||
public ObservableCollection<Gemeinde> OptionsGemeinde { get; private set; }
|
||||
@@ -66,10 +61,11 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public ICommand SaveCommand { get; private set; }
|
||||
public ICommand DeleteCommand { get; private set; }
|
||||
public ICommand DeleteConfirmCommand { get; private set; }
|
||||
//public ICommand LoadDataCommand { get; private set; }
|
||||
|
||||
|
||||
@@ -77,16 +73,17 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
|
||||
_stunde = new DayTime();
|
||||
|
||||
SaveCommand = new AsyncRelayCommand(Save);
|
||||
DeleteCommand = new AsyncRelayCommand(Delete);
|
||||
//DeleteCommand = new AsyncRelayCommand(Delete);
|
||||
DeleteConfirmCommand = new Command(async () => await DeleteConfirm());
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public StundeViewModel(DayTime stunde) {
|
||||
_stunde = stunde;
|
||||
|
||||
SaveCommand = new AsyncRelayCommand(Save);
|
||||
DeleteCommand = new AsyncRelayCommand(Delete);
|
||||
DeleteConfirmCommand = new AsyncRelayCommand(DeleteConfirm);
|
||||
}
|
||||
|
||||
private async Task LoadData() {
|
||||
@@ -118,10 +115,24 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
|
||||
await Shell.Current.GoToAsync($"..?date={_stunde.day.ToString("yyyy-MM-dd")}");
|
||||
}
|
||||
|
||||
private async Task DeleteConfirm() {
|
||||
if (ConfirmEvent != null) {
|
||||
bool answer = await ConfirmEvent.Invoke("Achtung", "Löschen kann nicht ungeschehen gemacht werden. Fortfahren?");
|
||||
if (answer) {
|
||||
//Löschen
|
||||
await Models.Stunde.DeleteEntry(_stunde);
|
||||
await Shell.Current.GoToAsync($"..?date={_stunde.day.ToString("yyyy-MM-dd")}");
|
||||
} else { //nicht Löschen
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
async void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query) {
|
||||
var probe = query;
|
||||
if (query.ContainsKey("load")) {
|
||||
|
||||
//DateTime heute = DateTime.Now;
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
<Grid ColumnDefinitions="*,*" ColumnSpacing="4">
|
||||
<Button Text="Speichern" Command="{Binding SaveCommand}" />
|
||||
<Button Grid.Column="1" Text="Löschen" Command="{Binding DeleteCommand}" />
|
||||
<Button Grid.Column="1" Text="Löschen" Command="{Binding DeleteConfirmCommand}" />
|
||||
</Grid>
|
||||
</VerticalStackLayout>
|
||||
</ContentPage>
|
||||
@@ -1,13 +1,30 @@
|
||||
using Jugenddienst_Stunden.Types;
|
||||
using System.ComponentModel;
|
||||
using Jugenddienst_Stunden.ViewModels;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Jugenddienst_Stunden.Views;
|
||||
|
||||
public partial class StundePage : ContentPage
|
||||
{
|
||||
public partial class StundePage : ContentPage {
|
||||
|
||||
public StundePage()
|
||||
{
|
||||
public ICommand DeleteConfirmCommand { get; }
|
||||
|
||||
public StundePage() {
|
||||
InitializeComponent();
|
||||
|
||||
if (BindingContext is StundeViewModel vm) {
|
||||
//vm.AlertEvent += Vm_AlertEvent;
|
||||
//vm.InfoEvent += Vm_InfoEvent;
|
||||
vm.ConfirmEvent += ShowConfirm;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Vm_AlertEvent(object? sender, string e) {
|
||||
DisplayAlert("Fehler:", e, "OK");
|
||||
}
|
||||
|
||||
|
||||
private async Task<bool> ShowConfirm(string title, string message) {
|
||||
return await DisplayAlert(title, message, "Passt!", "Na, nor decht nit.");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user