using Microsoft.AspNetCore.Components; using Duempelkas.App.Services; namespace Duempelkas.App.Components.Dialogs; public partial class EditCarryoverDialog { [Parameter] public decimal CurrentAmount { get; set; } [Parameter] public decimal InitialBalance { get; set; } [Parameter] public decimal CurrentEndBalance { get; set; } [Parameter] public int? Year { get; set; } [Parameter] public string AccountName { get; set; } = "Konto"; [Parameter] public EventCallback OnSave { get; set; } [Parameter] public EventCallback OnCancel { get; set; } private string amountText = string.Empty; private bool acknowledged; private bool initialized; private bool saving; private bool ValidAmount => BookingInput.TryBalance(amountText, out _); private decimal amount => BookingInput.TryBalance(amountText, out var value) ? value : CurrentAmount; private decimal Delta => amount - CurrentAmount; private static string Money(decimal value) => value.ToString("N2", System.Globalization.CultureInfo.GetCultureInfo("de-DE")) + " €"; protected override void OnParametersSet() { if (!initialized) { amountText = CurrentAmount.ToString("0.00", System.Globalization.CultureInfo.GetCultureInfo("de-DE")); initialized = true; } } private void ChangeAmount(string value) { amountText = value; acknowledged = false; } private async Task Save() { if (saving || !ValidAmount || !acknowledged || Delta == 0m) return; saving = true; try { await OnSave.InvokeAsync(amount); } catch (Exception ex) { Toasts.Show("Die Korrektur konnte nicht gespeichert werden. Bitte den aktuellen Bestand prüfen.", ToastKind.Error, ex.Message); } finally { saving = false; } } private Task Cancel() => modal?.RequestCloseAsync() ?? Task.CompletedTask; }