37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using LehrerApp.Core.Models;
|
|
using LehrerApp.Desktop.ViewModels.Groups;
|
|
using LehrerApp.Desktop.ViewModels.Planning;
|
|
using LehrerApp.Desktop.Views.Groups;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace LehrerApp.Desktop.Views.Planning;
|
|
|
|
public partial class WebUntisTimetableImportDialog : Window
|
|
{
|
|
public WebUntisTimetableImportDialog() => InitializeComponent();
|
|
|
|
private void OnCancel(object? sender, RoutedEventArgs e) => Close(false);
|
|
private void OnSave(object? sender, RoutedEventArgs e)
|
|
{
|
|
if (DataContext is WebUntisTimetableImportViewModel { Saved: true }) Close(true);
|
|
}
|
|
|
|
public async Task<LearningGroup?> CreateGroupAsync(WebUntisTimetableRow source)
|
|
{
|
|
var vm = App.Services.GetRequiredService<AddGroupDialogViewModel>();
|
|
vm.Name = source.SuggestedGroupName;
|
|
vm.Subject = source.SubjectName ?? "";
|
|
vm.GradeLevel = ParseGrade(source.SuggestedGroupName) ?? 10;
|
|
var dialog = new AddGroupDialog { DataContext = vm };
|
|
return await dialog.ShowDialog<bool>(this) ? vm.Result : null;
|
|
}
|
|
|
|
private static int? ParseGrade(string value)
|
|
{
|
|
var digits = new string(value.TakeWhile(char.IsDigit).ToArray());
|
|
return int.TryParse(digits, out var grade) && grade is >= 1 and <= 13 ? grade : null;
|
|
}
|
|
}
|