BudgetAnalyser.Engine.Services.TransactionManagerService.ImportAndMergeBankStatementAsync C# (CSharp) Method

ImportAndMergeBankStatementAsync() public method

Imports a bank's transaction extract and merges it with the currently loaded Budget Analyser Statement. This method should not be used without a StatementModel loaded. It is recommended to follow this up with ValidateWithCurrentBudgetsAsync.
/// /// There are no transactions loaded, you must first load an existing /// file or create a new one. ///
public ImportAndMergeBankStatementAsync ( string storageKey, Account account ) : System.Threading.Tasks.Task
storageKey string
account BudgetAnalyser.Engine.BankAccount.Account
return System.Threading.Tasks.Task
        public async Task ImportAndMergeBankStatementAsync(string storageKey, Account account)
        {
            if (storageKey.IsNothing())
            {
                throw new ArgumentNullException(nameof(storageKey));
            }

            if (account == null)
            {
                throw new ArgumentNullException(nameof(account));
            }

            if (StatementModel == null)
            {
                throw new InvalidOperationException(
                    "There are no transactions loaded, you must first load an existing file or create a new one.");
            }

            var additionalModel = await this.statementRepository.ImportBankStatementAsync(storageKey, account);
            var combinedModel = StatementModel.Merge(additionalModel);
            IEnumerable<IGrouping<int, Transaction>> duplicates = combinedModel.ValidateAgainstDuplicates();
            if (duplicates.Count() == additionalModel.AllTransactions.Count())
            {
                throw new TransactionsAlreadyImportedException();
            }

            StatementModel.Dispose();
            StatementModel = combinedModel;
            NewDataAvailable();
        }