using Avalonia.Controls; using LehrerApp.Core.Interfaces; using LehrerApp.Core.Models; using LehrerApp.Core.Services; using LehrerApp.Desktop.ViewModels.Planning; using LehrerApp.Desktop.ViewModels.Groups; using LehrerApp.Desktop.Views.Groups; using Microsoft.Extensions.DependencyInjection; namespace LehrerApp.Desktop.Views.Planning; public partial class TimetableView : UserControl { public TimetableView() => InitializeComponent(); protected override void OnDataContextChanged(EventArgs e) { base.OnDataContextChanged(e); if (DataContext is TimetableViewModel vm) { vm.OnEditSlot = ShowSlotDialog; vm.OnAddSubstitution = ShowSubstitutionDialog; vm.OnOpenLessonViewer = ShowLessonViewerDialog; vm.OnOpenTeachingMode = ShowTeachingMode; } } private async Task ShowTeachingMode(Lesson lesson) { var owner = TopLevel.GetTopLevel(this) as Window; var group = App.Services.GetRequiredService().GetById(lesson.GroupId); if (owner is null || group is null) return; var teachingModeVm = new TeachingModeViewModel(lesson, group, App.Services.GetRequiredService(), App.Services.GetRequiredService()); var window = new TeachingModeWindow { DataContext = teachingModeVm }; await window.ShowDialog(owner); } private async Task ShowLessonViewerDialog(Lesson lesson) { var owner = TopLevel.GetTopLevel(this) as Window; if (owner is null) return; var viewerVm = new LessonViewerViewModel(lesson, App.Services.GetRequiredService()); var dialog = new LessonViewerDialog { DataContext = viewerVm }; await dialog.ShowDialog(owner); } private async Task ShowSlotDialog(TimetableCellItem cell) { var owner = TopLevel.GetTopLevel(this) as Window; if (owner is null || cell.Weekday is null) return; var vm = new TimetableSlotDialogViewModel( App.Services.GetRequiredService(), App.Services.GetRequiredService(), App.Services.GetRequiredService(), App.Services.GetRequiredService(), cell.Weekday.Value, cell.PeriodNumber, cell.Slot); var dialog = new TimetableSlotDialog { DataContext = vm }; await dialog.ShowDialog(owner); } private async Task ShowSubstitutionDialog() { var owner = TopLevel.GetTopLevel(this) as Window; if (owner is null) return; var vm = new SubstitutionEntryDialogViewModel( App.Services.GetRequiredService(), App.Services.GetRequiredService(), App.Services.GetRequiredService(), App.Services.GetRequiredService()); var dialog = new SubstitutionEntryDialog { DataContext = vm }; await dialog.ShowDialog(owner); } }