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;
|
||||
|
||||
Reference in New Issue
Block a user