using Duempelkas.App.Services.Models; using Duempelkas.Domain.Enums; using Microsoft.AspNetCore.Components; namespace Duempelkas.App.Components.Dialogs; public partial class AddEntryDialog { #region Parameters [Parameter] public int AccountId { get; set; } [Parameter] public EntryDto? EditEntry { get; set; } [Parameter] public EventCallback OnSave { get; set; } [Parameter] public EventCallback OnCancel { get; set; } #endregion #region Fields private EntryType entryType = EntryType.Income; private DateTime date = DateTime.Today; private string title = string.Empty; private decimal amount; #endregion #region Lifecycle protected override void OnParametersSet() { if (EditEntry != null) { entryType = EditEntry.Type; date = EditEntry.Date; title = EditEntry.Title; amount = EditEntry.Amount; } } #endregion #region Actions private async Task Save() { if (EditEntry != null) { await EntryService.UpdateEntryAsync(EditEntry.Id, date, title.Trim(), amount); } else { await EntryService.CreateEntryAsync(AccountId, entryType, date, title.Trim(), amount); } await OnSave.InvokeAsync(); } private async Task Cancel() => await OnCancel.InvokeAsync(); #endregion }