public AccountHistoryDto GetAccountHistory(long accountId) { using (var context = new CashFlowContext()) { DataAccess.EF.Account efAccount = context.Account .Include(a => a.AccountBalance) .Include(a => a.TransferAccountFrom).ThenInclude(t => t.AccountTo) .Include(a => a.TransferAccountTo).ThenInclude(t => t.AccountFrom) .SingleOrDefault(t => t.Id == accountId); if (efAccount != null) { AccountBalance lastAccountBalance = efAccount.AccountBalance.OrderByDescending(b => b.StartDate).First(); AccountHistoryDto account = AccountHistoryMapper.Map( efAccount, lastAccountBalance, lastAccountBalance.Balance - efAccount.TransferAccountFrom.Sum(t => t.Amount) + efAccount.TransferAccountTo.Sum(t => t.Amount), efAccount.TransferAccountTo.OrderByDescending(t => t.TransferDate), efAccount.TransferAccountFrom.OrderByDescending(t => t.TransferDate)); return(account); } else { return(null); } } }
public AccountDto GetById(long accountId) { using (var context = new CashFlowContext()) { DataAccess.EF.Account efAccount = context.Account .Include(a => a.AccountBalance) .Include(a => a.TransferAccountFrom) .Include(a => a.TransferAccountTo) .SingleOrDefault(t => t.Id == accountId); if (efAccount != null) { AccountDto Account = AccountMapper.Map(efAccount, efAccount.AccountBalance.OrderByDescending(b => b.StartDate).First().Balance - efAccount.TransferAccountFrom.Sum(t => t.Amount) + efAccount.TransferAccountTo.Sum(t => t.Amount)); return(Account); } else { return(null); } } }