Working on a mini-banking app, and trying to make a page where the transactions into and out of a bank account are on display. I have a HomePage where I've able to display some data from the bank accounts, but for some reason I can't get any information to display on this page. I have one transaction saved in a JSON file that I want to display. This is the JSON file:
[
{
"Description": "Tree fiddy",
"Amount": 3.5,
"SourceAccountId": "6c7ac53a-5d65-4d5d-8898-f77283fe7cb6",
"DestinationAccountId": "737552b8-719b-4194-9d6f-74774e969e03"
}
]
This is the page I want to display the transaction data in:
Here's my ViewModel for the page:
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using ReadOnlyBankingSystem.Models;
using ReadOnlyBankingSystem.Services;
using System.Collections.ObjectModel;
namespace Frontend.ViewModels
{
[QueryProperty(nameof(BankAccount), "BankAccount")]
public partial class ViewTransactionsViewModel : BaseViewModel
{
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(Transactions))]
public partial BankAccount BankAccount { get; set; }
private ObservableCollection _transactions;
public ObservableCollection Transactions
{
//get => ledgerService.FilterTransactionsByAccountId(BankAccount.AccountId).Result;
get => ledgerService.GetTransactions().Result;
}
LedgerService ledgerService;
public ViewTransactionsViewModel(LedgerService ledgerService)
{
this.ledgerService = ledgerService;
this.BankAccount = new BlankAccount();
_transactions = new ObservableCollection();
}
}
}
Here is my Transaction class:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace ReadOnlyBankingSystem.Models
{
public class Transaction
{
[JsonInclude]
public readonly string Description;
[JsonInclude]
public readonly decimal Amount;
[JsonInclude]
public readonly Guid SourceAccountId;
[JsonInclude]
public readonly Guid DestinationAccountId;
public Transaction(Guid sourceAccountId, Guid destinationAccountId, decimal amount, string description)
{
Amount = amount;
Description = description;
SourceAccountId = sourceAccountId;
DestinationAccountId = destinationAccountId;
}
}
[JsonSerializable(typeof(ObservableCollection))]
internal sealed partial class TransactionContext : JsonSerializerContext
{
}
}
So, for a bit more context, I tested out this page by displaying a different bit of data from my Customer model and can confirm that that worked, so I figure the issue probably has to do with my Transaction class, but I can't tell what. Also, yes, I know I'm doing some things that aren't idiomatic. This is just a personal project I chose to work on to sharpen my skills and teach myself C# language features; I'll probably get to making DTOs and readonly properties at a later date.