47 lines
1.9 KiB
C#
47 lines
1.9 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using LehrerApp.Core.Models;
|
|
using System.Globalization;
|
|
|
|
namespace LehrerApp.Desktop.ViewModels.Students;
|
|
|
|
public sealed record GroupDocumentationOption(Guid Id, string DisplayName);
|
|
|
|
/// Kompakte Erfassung einer gruppenweiten Planungsnotiz aus der globalen Befehlspalette.
|
|
public partial class GroupDocumentationQuickViewModel(IEnumerable<GroupDocumentationOption> groups)
|
|
: ObservableObject
|
|
{
|
|
public List<GroupDocumentationOption> Groups { get; } = groups.ToList();
|
|
[ObservableProperty] private GroupDocumentationOption? _selectedGroup;
|
|
[ObservableProperty] private string _title = "";
|
|
[ObservableProperty] private string _content = "";
|
|
[ObservableProperty] private string _dateText = DateOnly.FromDateTime(DateTime.Today).ToString("dd.MM.yyyy");
|
|
[ObservableProperty] private string _groupError = "";
|
|
[ObservableProperty] private string _titleError = "";
|
|
[ObservableProperty] private string _dateError = "";
|
|
|
|
public Documentation? Result { get; private set; }
|
|
|
|
[RelayCommand]
|
|
private void Save()
|
|
{
|
|
GroupError = TitleError = DateError = "";
|
|
if (SelectedGroup is null) GroupError = "Lerngruppe auswählen.";
|
|
if (string.IsNullOrWhiteSpace(Title)) TitleError = "Titel erforderlich.";
|
|
if (!DateOnly.TryParseExact(DateText, "dd.MM.yyyy", null, DateTimeStyles.None, out var date))
|
|
DateError = "Format TT.MM.JJJJ.";
|
|
if (GroupError.Length > 0 || TitleError.Length > 0 || DateError.Length > 0) return;
|
|
|
|
Result = new Documentation
|
|
{
|
|
StudentId = Guid.Empty,
|
|
GroupId = SelectedGroup!.Id,
|
|
Type = DocumentationType.Planning,
|
|
Date = date,
|
|
Title = Title.Trim(),
|
|
Content = Content.Trim(),
|
|
ExcludeFromWebUntisSync = true,
|
|
};
|
|
}
|
|
}
|