diff --git a/src/Money.Blazor.Host/Pages/Test.razor b/src/Money.Blazor.Host/Pages/Test.razor index b33eb87b..2869bd8d 100644 --- a/src/Money.Blazor.Host/Pages/Test.razor +++ b/src/Money.Blazor.Host/Pages/Test.razor @@ -1,38 +1,37 @@ @page "/test" + + <div style="margin-top: 5rem;"> - @if (Balances == null) + @if (ExpenseTemplates == null) { <em>Loading...</em> } else { <table> - <tr> - <td> - Month - </td> - <td> - Expenses - </td> - <td> - Incomes - </td> - </tr> - @foreach (var balance in Balances) + @foreach (var expenseTemplate in ExpenseTemplates) { <tr> <td> - @balance + @expenseTemplate.Key + </td> + <td> + @expenseTemplate.Amount </td> <td> - @balance.ExpenseSummary + @expenseTemplate.Description </td> <td> - @balance.IncomeSummary + @expenseTemplate.CategoryKey + </td> + <td> + <button class="btn btn-small btn-danger" @onclick="async () => await Commands.HandleAsync(new DeleteExpenseTemplate(expenseTemplate.Key))">Delete</button> </td> </tr> } </table> + + <button class="btn btn-primary" @onclick="CreateAsync">Create expense template</button> } </div> \ No newline at end of file diff --git a/src/Money.Blazor.Host/Pages/Test.razor.cs b/src/Money.Blazor.Host/Pages/Test.razor.cs index d1ba2094..9d73ae91 100644 --- a/src/Money.Blazor.Host/Pages/Test.razor.cs +++ b/src/Money.Blazor.Host/Pages/Test.razor.cs @@ -3,6 +3,7 @@ using Money.Events; using Money.Models; using Money.Models.Queries; +using Neptuo; using Neptuo.Commands; using Neptuo.Events; using Neptuo.Events.Handlers; @@ -17,7 +18,7 @@ namespace Money.Pages { - public partial class Test + public partial class Test : System.IDisposable, IEventHandler<ExpenseTemplateCreated>, IEventHandler<ExpenseTemplateDeleted> { [Inject] protected IQueryDispatcher Queries { get; set; } @@ -28,13 +29,43 @@ public partial class Test [Inject] protected IEventHandlerCollection EventHandlers { get; set; } - protected List<MonthBalanceModel> Balances { get; set; } + protected List<ExpenseTemplateModel> ExpenseTemplates { get; set; } protected async override Task OnInitializedAsync() { await base.OnInitializedAsync(); + await LoadAsync(); - Balances = await Queries.QueryAsync(new ListMonthBalance(DateTime.Now)); + EventHandlers.Add<ExpenseTemplateCreated>(this); + EventHandlers.Add<ExpenseTemplateDeleted>(this); + } + + public void Dispose() + { + EventHandlers.Remove<ExpenseTemplateCreated>(this); + EventHandlers.Remove<ExpenseTemplateDeleted>(this); + } + + private async Task LoadAsync() + { + ExpenseTemplates = await Queries.QueryAsync(new ListAllExpenseTemplate()); + } + + protected async Task CreateAsync() + { + await Commands.HandleAsync(new CreateExpenseTemplate(new Price(2500, "CZK"), "2.5K", KeyFactory.Empty(typeof(Category)))); + } + + public async Task HandleAsync(ExpenseTemplateCreated payload) + { + await LoadAsync(); + StateHasChanged(); + } + + public async Task HandleAsync(ExpenseTemplateDeleted payload) + { + await LoadAsync(); + StateHasChanged(); } } }