using Duempelkas.App.Services.Models; using Microsoft.AspNetCore.Components; namespace Duempelkas.App.Components.Dialogs; public partial class AddTransferDialog { #region Parameters [Parameter] public int SourceAccountId { get; set; } [Parameter] public EntryDto? EditEntry { get; set; } [Parameter] public EventCallback OnSave { get; set; } [Parameter] public EventCallback OnCancel { get; set; } #endregion #region Fields private List accounts = new(); private int targetAccountId; private DateTime date = DateTime.Today; private string title = string.Empty; private decimal amount; #endregion #region Properties private bool CanSave => targetAccountId > 0 && !string.IsNullOrWhiteSpace(title) && amount > 0; #endregion #region Lifecycle protected override async Task OnParametersSetAsync() { if (!accounts.Any()) { accounts = await AccountService.GetAllAccountsAsync(); } if (EditEntry != null) { targetAccountId = EditEntry.LinkedAccountId ?? 0; date = EditEntry.Date; title = EditEntry.Title; amount = EditEntry.Amount; } } #endregion #region Actions private async Task Save() { if (EditEntry != null) { await EntryService.UpdateTransferAsync(EditEntry.Id, targetAccountId, date, title.Trim(), amount); } else { await EntryService.CreateTransferAsync(SourceAccountId, targetAccountId, date, title.Trim(), amount); } await OnSave.InvokeAsync(); } private async Task Cancel() => await OnCancel.InvokeAsync(); #endregion }