using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using LehrerApp.Core.Interfaces; using LehrerApp.Core.Models; using LehrerApp.Core.Services; using LehrerApp.Data; using LehrerApp.Desktop.Services; using LehrerApp.Desktop.ViewModels.Planning; using LehrerApp.Sync; using LehrerApp.Sync.Crypto; using System.Collections.ObjectModel; using System.Globalization; using System.Security.Cryptography; using System.Text.Json; using System.Text.Json.Serialization; namespace LehrerApp.Desktop.ViewModels.Settings; public partial class SettingsViewModel { // ── Kürzel-Katalog (Stundenverlaufsplan, 4.2.2) ────────────────────────── [ObservableProperty] private string _newShorthandCode = ""; [ObservableProperty] private string _newShorthandLabel = ""; [ObservableProperty] private string _newShorthandCodeError = ""; public ObservableCollection ShorthandCodes { get; } = []; // ── Kürzel-Katalog: Laden / Hinzufügen / Löschen ───────────────────────── public void LoadShorthandCodes() { ShorthandCodes.Clear(); foreach (var c in _shorthandCodes.GetAll()) ShorthandCodes.Add(new ShorthandCodeListItem(c)); } [RelayCommand] private void AddShorthandCode() { if (string.IsNullOrWhiteSpace(NewShorthandCode)) { NewShorthandCodeError = "Kürzel erforderlich."; return; } try { _shorthandCodes.Save(new ShorthandCode { Code = NewShorthandCode.Trim(), Label = NewShorthandLabel.Trim() }); } catch (InvalidOperationException ex) { NewShorthandCodeError = ex.Message; return; } NewShorthandCode = ""; NewShorthandLabel = ""; NewShorthandCodeError = ""; LoadShorthandCodes(); } [RelayCommand] private void DeleteShorthandCode(ShorthandCodeListItem? item) { if (item is null) return; _shorthandCodes.Delete(item.Id); LoadShorthandCodes(); } } public class ShorthandCodeListItem(ShorthandCode c) { public Guid Id { get; } = c.Id; public string Code { get; } = c.Code; public string Label { get; } = c.Label; }