Confirm Delete
This commit is contained in:
@@ -1,13 +1,7 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using Jugenddienst_Stunden.Models;
|
|
||||||
using Jugenddienst_Stunden.Types;
|
using Jugenddienst_Stunden.Types;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.ViewModels;
|
namespace Jugenddienst_Stunden.ViewModels;
|
||||||
@@ -24,6 +18,7 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
|
|||||||
|
|
||||||
public event EventHandler<string> AlertEvent;
|
public event EventHandler<string> AlertEvent;
|
||||||
public event EventHandler<string> InfoEvent;
|
public event EventHandler<string> InfoEvent;
|
||||||
|
public event Func<string, string, Task<bool>> ConfirmEvent;
|
||||||
|
|
||||||
|
|
||||||
public ObservableCollection<Gemeinde> OptionsGemeinde { get; private set; }
|
public ObservableCollection<Gemeinde> OptionsGemeinde { get; private set; }
|
||||||
@@ -70,6 +65,7 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
|
|||||||
|
|
||||||
public ICommand SaveCommand { get; private set; }
|
public ICommand SaveCommand { get; private set; }
|
||||||
public ICommand DeleteCommand { get; private set; }
|
public ICommand DeleteCommand { get; private set; }
|
||||||
|
public ICommand DeleteConfirmCommand { get; private set; }
|
||||||
//public ICommand LoadDataCommand { get; private set; }
|
//public ICommand LoadDataCommand { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
@@ -77,7 +73,8 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
|
|||||||
_stunde = new DayTime();
|
_stunde = new DayTime();
|
||||||
|
|
||||||
SaveCommand = new AsyncRelayCommand(Save);
|
SaveCommand = new AsyncRelayCommand(Save);
|
||||||
DeleteCommand = new AsyncRelayCommand(Delete);
|
//DeleteCommand = new AsyncRelayCommand(Delete);
|
||||||
|
DeleteConfirmCommand = new Command(async () => await DeleteConfirm());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -86,7 +83,7 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
|
|||||||
_stunde = stunde;
|
_stunde = stunde;
|
||||||
|
|
||||||
SaveCommand = new AsyncRelayCommand(Save);
|
SaveCommand = new AsyncRelayCommand(Save);
|
||||||
DeleteCommand = new AsyncRelayCommand(Delete);
|
DeleteConfirmCommand = new AsyncRelayCommand(DeleteConfirm);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task LoadData() {
|
private async Task LoadData() {
|
||||||
@@ -118,10 +115,24 @@ internal class StundeViewModel : ObservableObject, IQueryAttributable {
|
|||||||
await Shell.Current.GoToAsync($"..?date={_stunde.day.ToString("yyyy-MM-dd")}");
|
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) {
|
async void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query) {
|
||||||
|
var probe = query;
|
||||||
if (query.ContainsKey("load")) {
|
if (query.ContainsKey("load")) {
|
||||||
|
|
||||||
//DateTime heute = DateTime.Now;
|
//DateTime heute = DateTime.Now;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
<Grid ColumnDefinitions="*,*" ColumnSpacing="4">
|
<Grid ColumnDefinitions="*,*" ColumnSpacing="4">
|
||||||
<Button Text="Speichern" Command="{Binding SaveCommand}" />
|
<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>
|
</Grid>
|
||||||
</VerticalStackLayout>
|
</VerticalStackLayout>
|
||||||
</ContentPage>
|
</ContentPage>
|
||||||
@@ -1,13 +1,30 @@
|
|||||||
using Jugenddienst_Stunden.Types;
|
using Jugenddienst_Stunden.ViewModels;
|
||||||
using System.ComponentModel;
|
using System.Windows.Input;
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.Views;
|
namespace Jugenddienst_Stunden.Views;
|
||||||
|
|
||||||
public partial class StundePage : ContentPage
|
public partial class StundePage : ContentPage {
|
||||||
{
|
|
||||||
|
|
||||||
public StundePage()
|
public ICommand DeleteConfirmCommand { get; }
|
||||||
{
|
|
||||||
|
public StundePage() {
|
||||||
InitializeComponent();
|
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