70 lines
2.8 KiB
C#
70 lines
2.8 KiB
C#
using Avalonia.Controls;
|
|
using LehrerApp.Desktop.ViewModels.Groups;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace LehrerApp.Desktop.Views.Groups;
|
|
|
|
public partial class GroupListView : UserControl
|
|
{
|
|
public GroupListView() => InitializeComponent();
|
|
|
|
protected override void OnDataContextChanged(EventArgs e)
|
|
{
|
|
base.OnDataContextChanged(e);
|
|
if (DataContext is GroupListViewModel vm)
|
|
{
|
|
vm.OnAddGroup = ShowAddGroupDialog;
|
|
vm.OnEditGroup = ShowEditGroupDialog;
|
|
vm.OnRollOverGroup = ShowGroupRolloverDialog;
|
|
vm.OnConfirmDelete = ShowDeleteGroupDialog;
|
|
}
|
|
}
|
|
|
|
private async Task ShowAddGroupDialog()
|
|
{
|
|
var dialogVm = App.Services.GetRequiredService<AddGroupDialogViewModel>();
|
|
var dialog = new AddGroupDialog { DataContext = dialogVm };
|
|
var owner = TopLevel.GetTopLevel(this) as Window;
|
|
if (owner is not null)
|
|
await dialog.ShowDialog(owner);
|
|
}
|
|
|
|
private async Task ShowEditGroupDialog(Guid groupId)
|
|
{
|
|
var group = App.Services.GetRequiredService<LehrerApp.Core.Interfaces.IGroupRepository>()
|
|
.GetById(groupId);
|
|
if (group is null) return;
|
|
|
|
var dialogVm = App.Services.GetRequiredService<AddGroupDialogViewModel>();
|
|
dialogVm.LoadForEdit(group);
|
|
var dialog = new AddGroupDialog { DataContext = dialogVm };
|
|
var owner = TopLevel.GetTopLevel(this) as Window;
|
|
if (owner is not null)
|
|
await dialog.ShowDialog<bool>(owner);
|
|
}
|
|
|
|
private async Task<Guid?> ShowGroupRolloverDialog(Guid groupId)
|
|
{
|
|
var group = App.Services.GetRequiredService<LehrerApp.Core.Interfaces.IGroupRepository>()
|
|
.GetById(groupId);
|
|
var owner = TopLevel.GetTopLevel(this) as Window;
|
|
if (group is null || owner is null) return null;
|
|
|
|
var dialogVm = new GroupRolloverDialogViewModel(group,
|
|
App.Services.GetRequiredService<LehrerApp.Core.Interfaces.IStudentRepository>(),
|
|
App.Services.GetRequiredService<LehrerApp.Core.Interfaces.IGroupMembershipRepository>(),
|
|
App.Services.GetRequiredService<LehrerApp.Core.Interfaces.IGradingSchemeRepository>(),
|
|
App.Services.GetRequiredService<LehrerApp.Core.Services.SchoolYearService>(),
|
|
App.Services.GetRequiredService<LehrerApp.Core.Services.GroupRolloverService>());
|
|
var dialog = new GroupRolloverDialog { DataContext = dialogVm };
|
|
return await dialog.ShowDialog<Guid?>(owner);
|
|
}
|
|
|
|
private async Task<bool> ShowDeleteGroupDialog(GroupListItem group)
|
|
{
|
|
var dialog = new DeleteGroupDialog { DataContext = group.DisplayName };
|
|
var owner = TopLevel.GetTopLevel(this) as Window;
|
|
return owner is not null && await dialog.ShowDialog<bool>(owner);
|
|
}
|
|
}
|