AccountingNext/Schaad.Accounting.UI/Components/Pages/Dialogs/TransactionDialog.razor.cs
Claudio Schaad 70f9ce0d58 PR U-2: guard TransactionDialog.SaveAsync against a cleared date
Guard SaveAsync against a null SelectedValue (previously
SelectedValue!.Value threw InvalidOperationException) and disable
the Save button while the date is empty so the user gets a visible
cue.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-07-04 08:32:34 +02:00

54 lines
No EOL
1.5 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.FluentUI.AspNetCore.Components;
using Schaad.Accounting.Interfaces;
using Schaad.Accounting.Models;
namespace Schaad.Accounting.UI.Components.Pages.Dialogs;
public partial class TransactionDialog : ComponentBase
{
private EditContext? editContext;
[CascadingParameter]
public FluentDialog Dialog { get; set; } = null!;
[Parameter]
public Transaction Content { get; set; } = null!;
[Inject]
private ITransactionRepository transactionRepository { get; set; } = null!;
[Inject]
private IViewService viewService { get; set; } = null!;
private IReadOnlyList<Account> accounts = [];
private DateTime? SelectedValue;
protected override async Task OnInitializedAsync()
{
SelectedValue = Content.ValueDate;
editContext = new EditContext(Content);
accounts = await viewService.GetAccountViewListAsync();
}
private async Task SaveAsync()
{
if (editContext is null || SelectedValue is null)
{
return;
}
if (editContext.Validate())
{
Content.ValueDate = SelectedValue.Value;
Content.BookingDate = SelectedValue.Value;
await transactionRepository.SaveTransactionAsync(Content);
await Dialog.CloseAsync(Content);
}
}
private async Task CancelAsync()
{
await Dialog.CancelAsync();
}
}