public BudgetTransactionListViewModelFactory( ILoggerFactory loggerFactory, IAccountService accountService, IBudgetService budgetService, IAccountLinkViewModelFactory accountLinkViewModelFactory, IBudgetTransactionItemViewModelFactory budgetTransactionItemViewModelFactory, IDeleteConfirmationViewService deleteConfirmationViewService) { m_loggerFactory = loggerFactory; m_accountService = accountService; m_budgetService = budgetService; m_accountLinkViewModelFactory = accountLinkViewModelFactory; m_budgetTransactionItemViewModelFactory = budgetTransactionItemViewModelFactory; m_deleteConfirmationViewService = deleteConfirmationViewService; }
public BudgetTransactionListViewModel( ILoggerFactory loggerFactory, IAccountService accountService, IBudgetService budgetService, IAccountLinkViewModelFactory accountLinkViewModelFactory, IBudgetTransactionItemViewModelFactory budgetTransactionItemViewModelFactory, IDeleteConfirmationViewService deleteConfirmationViewService, int budgetId) { m_logger = loggerFactory.CreateLogger <BudgetTransactionListViewModel>(); m_accountService = accountService; m_budgetService = budgetService; m_accountLinkViewModelFactory = accountLinkViewModelFactory; m_budgetTransactionItemViewModelFactory = budgetTransactionItemViewModelFactory; m_deleteConfirmationViewService = deleteConfirmationViewService; m_accountLinks = new ObservableCollection <IAccountLinkViewModel>( m_accountService .GetAllAsLinks() .OrderBy(al => al.Name) .Select(al => m_accountLinkViewModelFactory.Create(al))); m_budgetId = budgetId; if (m_budgetId == 0) { int firstIncomeAccountId = 0; int firstAssetAccountId = 0; int secondAssetAccountId = 0; IAccountLinkViewModel firstIncomeAccount = m_accountLinks.FirstOrDefault(al => al.Type == AccountType.Income); IAccountLinkViewModel firstAssetAccount = m_accountLinks.FirstOrDefault(al => al.Type == AccountType.Asset); IAccountLinkViewModel secondAssetAccount = m_accountLinks.Where(al => al.Type == AccountType.Asset) .ElementAtOrDefault(1); if (firstIncomeAccount != null) { firstIncomeAccountId = firstIncomeAccount.AccountId; } if (firstAssetAccount != null) { firstAssetAccountId = secondAssetAccount.AccountId; } if (secondAssetAccount != null) { secondAssetAccountId = secondAssetAccount.AccountId; } var transactions = new List <IBudgetTransactionItemViewModel>(); BudgetTransaction initialTransaction = new BudgetTransaction { CreditAccount = new AccountLink { AccountId = firstIncomeAccountId }, DebitAccount = new AccountLink { AccountId = firstAssetAccountId }, Amount = 0 }; BudgetTransaction surplusTransaction = new BudgetTransaction { CreditAccount = new AccountLink { AccountId = firstAssetAccountId }, DebitAccount = new AccountLink { AccountId = secondAssetAccountId }, Amount = 0 }; transactions.Add(CreateItemViewModel(initialTransaction, BudgetTransactionType.Initial)); transactions.Add(CreateItemViewModel(surplusTransaction, BudgetTransactionType.Surplus)); Transactions = new ObservableCollection <IBudgetTransactionItemViewModel>(transactions); } else { Budget budget = m_budgetService.Get(m_budgetId); var transactions = new List <IBudgetTransactionItemViewModel>(); transactions.Add(CreateItemViewModel(budget.InitialTransaction, BudgetTransactionType.Initial)); transactions.AddRange( budget.Transactions.Select(t => CreateItemViewModel(t, BudgetTransactionType.Regular)) ); transactions.Add(CreateItemViewModel(budget.SurplusTransaction, BudgetTransactionType.Surplus)); Transactions = new ObservableCollection <IBudgetTransactionItemViewModel>(transactions); } CalculateSurplusAmount(); }