public decimal GetBalance() { decimal currentBalance = 0.00m; //This is a 'hacky' implementation. //In a production system, this would be based on date, not ID //There would also be cleaner separation between read and write models (think cqrs) BalanceSnapshot lastSnapshot = GetMostRecentSnapshot(); if (lastSnapshot != null) { var trxsSinceSnapshot = AccountRecords.Where(t => t.TransactionID > lastSnapshot.TransactionID); currentBalance = SumTransactions(trxsSinceSnapshot) + lastSnapshot.Balance; } else { currentBalance = SumTransactions(AccountRecords); } return(currentBalance); }
public async Task UpdateBalance(BalanceSnapshot snapshot) { await Clients.All.SendAsync("UpdateBalance", snapshot); }