47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
using Avalonia.Controls;
|
|
using LehrerApp.Core.Models;
|
|
using LehrerApp.Desktop.ViewModels.Groups;
|
|
using LehrerApp.Desktop.Views.Shared;
|
|
|
|
namespace LehrerApp.Desktop.Views.Groups;
|
|
|
|
public partial class SeatingPlanTabView : UserControl
|
|
{
|
|
public SeatingPlanTabView() => InitializeComponent();
|
|
|
|
protected override void OnDataContextChanged(EventArgs e)
|
|
{
|
|
base.OnDataContextChanged(e);
|
|
if (DataContext is SeatingPlanTabViewModel vm)
|
|
{
|
|
vm.OnEditPlan = ShowPlanDialog;
|
|
vm.OnConfirmDelete = ShowDeleteConfirmDialog;
|
|
}
|
|
}
|
|
|
|
private async Task<SeatingPlan?> ShowPlanDialog(SeatingPlan? plan)
|
|
{
|
|
if (DataContext is not SeatingPlanTabViewModel vm) return null;
|
|
var dialogVm = vm.CreateDialogViewModel(plan);
|
|
var dialog = new SeatingPlanDialog { DataContext = dialogVm };
|
|
var owner = TopLevel.GetTopLevel(this) as Window;
|
|
if (owner is null || !await dialog.ShowDialog<bool>(owner)) return null;
|
|
return dialogVm.Result;
|
|
}
|
|
|
|
private async Task<bool> ShowDeleteConfirmDialog(SeatingPlanSummary plan)
|
|
{
|
|
var dialog = new ConfirmDialog
|
|
{
|
|
DataContext = new ConfirmDialogInfo
|
|
{
|
|
Title = "Sitzplan löschen?",
|
|
Message = $"Der Sitzplan „{plan.Name}“ und seine Zuordnungen werden gelöscht.",
|
|
ConfirmText = "Löschen",
|
|
},
|
|
};
|
|
var owner = TopLevel.GetTopLevel(this) as Window;
|
|
return owner is not null && await dialog.ShowDialog<bool>(owner);
|
|
}
|
|
}
|