Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 public async Task UpdateBalance(BalanceSnapshot snapshot)
 {
     await Clients.All.SendAsync("UpdateBalance", snapshot);
 }