using Avalonia.Controls; using LehrerApp.Core.Interfaces; using LehrerApp.Core.Models; using LehrerApp.Core.Services; using LehrerApp.Desktop.ViewModels; using LehrerApp.Desktop.ViewModels.Exams; using LehrerApp.Desktop.ViewModels.Groups; using LehrerApp.Desktop.Views.Groups; using Microsoft.Extensions.DependencyInjection; namespace LehrerApp.Desktop.Views.Exams; public partial class ExamsOverviewView : UserControl { private const int GroupDetailKlausurenTabIndex = 4; public ExamsOverviewView() => InitializeComponent(); protected override void OnDataContextChanged(EventArgs e) { base.OnDataContextChanged(e); if (DataContext is ExamsOverviewViewModel vm) { vm.OnGradeExam = ShowGradeExamDialog; vm.OnEvaluateExam = ShowEvaluateExamDialog; vm.OnNavigateToGroup = groupId => App.Services.GetRequiredService() .NavigateToGroupDetail(groupId, GroupDetailKlausurenTabIndex); } } private async Task ShowGradeExamDialog(Exam exam) { var group = App.Services.GetRequiredService().GetById(exam.GroupId); if (group is null) return; var dialogVm = new ExamGradingDialogViewModel( App.Services.GetRequiredService(), App.Services.GetRequiredService(), App.Services.GetRequiredService(), App.Services.GetRequiredService(), exam, group.Id); var dialog = new ExamGradingDialog { DataContext = dialogVm }; var owner = TopLevel.GetTopLevel(this) as Window; if (owner is not null) await dialog.ShowDialog(owner); } private async Task ShowEvaluateExamDialog(Exam exam) { var group = App.Services.GetRequiredService().GetById(exam.GroupId); if (group is null) return; var dialogVm = new ExamEvaluationDialogViewModel( App.Services.GetRequiredService(), App.Services.GetRequiredService(), App.Services.GetRequiredService(), exam, group.GradingSystem); var dialog = new ExamEvaluationDialog { DataContext = dialogVm }; var owner = TopLevel.GetTopLevel(this) as Window; if (owner is not null) await dialog.ShowDialog(owner); } }