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.Load( transactionData.Id, transactionData.AccountId, transactionData.Amount, transactionData.TransactionDate); transactions.Add(transaction); } foreach (Entities.Debit transactionData in debits) { Debit transaction = Debit.Load( 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.Load( account.Id, account.CustomerId, transactionCollection); return(result); }
public async Task Add(Account account, Credit credit) { Entities.Account accountEntity = new Entities.Account() { CustomerId = account.CustomerId, Id = account.Id }; Entities.Credit creditEntity = new Entities.Credit() { AccountId = credit.AccountId, Amount = credit.Amount, Id = credit.Id, TransactionDate = credit.TransactionDate }; await _context.Accounts.AddAsync(accountEntity); await _context.Credits.AddAsync(creditEntity); await _context.SaveChangesAsync(); }