Files
LehrerApp/LehrerApp.Desktop/Views/Groups/GroupDetailView.axaml.cs
T

36 lines
1.1 KiB
C#

using Avalonia.Controls;
using LehrerApp.Core.Interfaces;
using LehrerApp.Desktop.ViewModels.Groups;
using Microsoft.Extensions.DependencyInjection;
namespace LehrerApp.Desktop.Views.Groups;
public partial class GroupDetailView : UserControl
{
public GroupDetailView() => InitializeComponent();
protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);
if (DataContext is GroupDetailViewModel vm)
vm.OnAddStudent = ShowAddStudentDialog;
}
private async Task<bool> ShowAddStudentDialog()
{
if (DataContext is not GroupDetailViewModel vm || vm.Group is null) return false;
var dialogVm = new AddStudentToGroupDialogViewModel(
App.Services.GetRequiredService<IStudentRepository>(),
App.Services.GetRequiredService<IEnrollmentRepository>(),
vm.Group.Id,
vm.Group.SchoolYear);
var dialog = new AddStudentToGroupDialog { DataContext = dialogVm };
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return false;
return await dialog.ShowDialog<bool>(owner);
}
}