示例#1
0
        public async Task <Account> Get(Guid id)
        {
            Entities.Account account = await _context
                                       .Accounts
                                       .FindAsync(id);

            List <Entities.Credit> credits = await _context
                                             .Credits
                                             .Where(e => e.AccountId == id)
                                             .ToListAsync();

            List <Entities.Debit> debits = await _context
                                           .Debits
                                           .Where(e => e.AccountId == id)
                                           .ToListAsync();

            List <ITransaction> transactions = new List <ITransaction>();

            foreach (Entities.Credit transactionData in credits)
            {
                Credit transaction = Credit.LoadFromDetails(
                    transactionData.Id,
                    transactionData.AccountId,
                    transactionData.Amount,
                    transactionData.TransactionDate);

                transactions.Add(transaction);
            }

            foreach (Entities.Debit transactionData in debits)
            {
                Debit transaction = Debit.LoadFromDetails(
                    transactionData.Id,
                    transactionData.AccountId,
                    transactionData.Amount,
                    transactionData.TransactionDate);

                transactions.Add(transaction);
            }

            var orderedTransactions = transactions.OrderBy(o => o.TransactionDate).ToList();

            TransactionCollection transactionCollection = new TransactionCollection();

            transactionCollection.Add(orderedTransactions);

            Account result = Account.LoadFromDetails(
                account.Id,
                account.CustomerId,
                transactionCollection);

            return(result);
        }
示例#2
0
        public void Debit_Should_Be_Loaded()
        {
            Debit debit = Debit.LoadFromDetails(
                Guid.Empty,
                Guid.Empty,
                100,
                DateTime.Today);

            Assert.Equal(Guid.Empty, debit.Id);
            Assert.Equal(Guid.Empty, debit.AccountId);
            Assert.Equal(100, debit.Amount);
            Assert.Equal(DateTime.Today, debit.TransactionDate);
            Assert.Equal("Debit", debit.Description);
        }