Exemple #1
0
 public decimal GetAccountBalance(string account)
 {
     using (CAP_EventSourcingEntities entities = new CAP_EventSourcingEntities())
     {
         DateTime dateOfBusiness = AccountUtility.GetDateOfBusiness(entities);
         DateTime snapshotDate   = dateOfBusiness - TimeSpan.FromDays(2.0);
         return(AccountUtility.GetAccountBalance(account, snapshotDate, dateOfBusiness, entities));
     }
 }
Exemple #2
0
        // TODO 3d: Command is just an insert.
        public void Transfer(string fromAccount, string toAccount, decimal amount)
        {
            using (CAP_EventSourcingEntities entities = new CAP_EventSourcingEntities())
            {
                DateTime dateOfBusiness = AccountUtility.GetDateOfBusiness(entities);
                DateTime snapshotDate   = dateOfBusiness - TimeSpan.FromDays(2.0);
                decimal  accountBalance = AccountUtility.GetAccountBalance(fromAccount, snapshotDate, dateOfBusiness, entities);

                if (accountBalance < amount)
                {
                    throw new ApplicationException("Insufficient funds");
                }

                entities.AddToTransfers(new Transfer()
                {
                    From           = fromAccount,
                    To             = toAccount,
                    Amount         = amount,
                    DateOfBusiness = dateOfBusiness
                });

                entities.SaveChanges();
            }
        }