using Avalonia.Controls; using LehrerApp.Core.Interfaces; using LehrerApp.Core.Models; using LehrerApp.Desktop.ViewModels.ClassTeacher; using LehrerApp.Desktop.ViewModels.Students; using LehrerApp.Desktop.Views.Shared; using LehrerApp.Desktop.Views.Students; using Microsoft.Extensions.DependencyInjection; namespace LehrerApp.Desktop.Views.ClassTeacher; public partial class ClassTeacherCasesView : UserControl { public ClassTeacherCasesView() => InitializeComponent(); protected override void OnDataContextChanged(EventArgs e) { base.OnDataContextChanged(e); if (DataContext is not ClassTeacherCasesViewModel vm) return; vm.OnEditVorgang = ShowVorgangDialog; vm.OnConfirmDeleteVorgang = ShowDeleteVorgangDialog; vm.OnEditDocumentation = ShowDocumentationDialog; } private async Task ShowVorgangDialog(List rosterStudents, Vorgang? editing) { var owner = TopLevel.GetTopLevel(this) as Window; if (owner is null) return null; var vm = new VorgangDialogViewModel(rosterStudents, editing); var dialog = new VorgangDialog { DataContext = vm }; var saved = await dialog.ShowDialog(owner); return saved ? vm.Result : null; } private async Task ShowDeleteVorgangDialog(VorgangItem item) { var info = new ConfirmDialogInfo { Title = "Vorgang löschen?", Message = $"\"{item.Model.Title}\" wird als gelöscht markiert und nicht mehr angezeigt. " + "Verknüpfte Dokumentation bleibt erhalten.", ConfirmText = "Löschen", }; var dialog = new ConfirmDialog { DataContext = info }; var owner = TopLevel.GetTopLevel(this) as Window; return owner is not null && await dialog.ShowDialog(owner); } private async Task ShowDocumentationDialog( Guid defaultStudentId, List studentOptions, Documentation? editing) { var owner = TopLevel.GetTopLevel(this) as Window; if (owner is null) return null; var vm = new DocumentationDialogViewModel(defaultStudentId, editing, App.Services.GetRequiredService(), studentOptions); var dialog = new DocumentationDialog { DataContext = vm }; var saved = await dialog.ShowDialog(owner); if (!saved) vm.DiscardUnsavedAttachments(); return saved ? vm.Result : null; } }