TimetableSlotDialogViewModel baute die Gruppenauswahl als Dictionary,
geschlüsselt nach LearningGroup.Name. Bei zwei Lerngruppen mit demselben
Namen (dieselbe Klasse in zwei Fächern unterrichtet, z.B. zwei "10c") warf
ToDictionary eine ArgumentException, der Zuweisen-Dialog ließ sich gar
nicht mehr öffnen.
Behoben durch eindeutige Anzeige-Labels statt des rohen Namens: bei einem
Namenskonflikt wird das Fach angehängt ("10c (Chemie)" vs. "10c
(Mathematik)"), mit nummeriertem Fallback für den Restfall gleicher Name
und gleiches Fach.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
54 lines
1.9 KiB
C#
54 lines
1.9 KiB
C#
using Avalonia.Controls;
|
|
using LehrerApp.Core.Interfaces;
|
|
using LehrerApp.Core.Services;
|
|
using LehrerApp.Desktop.ViewModels.Planning;
|
|
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;
|
|
}
|
|
}
|
|
|
|
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<ITimetableSlotRepository>(),
|
|
App.Services.GetRequiredService<IGroupRepository>(),
|
|
App.Services.GetRequiredService<ISubjectRepository>(),
|
|
App.Services.GetRequiredService<SchoolYearService>(),
|
|
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<ISubstitutionEntryRepository>(),
|
|
App.Services.GetRequiredService<IGroupRepository>(),
|
|
App.Services.GetRequiredService<IUnitRepository>(),
|
|
App.Services.GetRequiredService<ILessonRepository>());
|
|
|
|
var dialog = new SubstitutionEntryDialog { DataContext = vm };
|
|
await dialog.ShowDialog(owner);
|
|
}
|
|
}
|