public override void Execute(Task task)
        {
            try
            {
                if (_settings.IsDemo == false)
                {
                    base.Execute(task);
                    return;
                }

                foreach (Client client in _clientDataService.GetAllClients())
                {
                    List <Transaction> transactions = _transactionsDataService.GetTransactions(client.ID);
                    foreach (Transaction transaction in transactions)
                    {
                        if (transaction.Owner == "User")
                        {
                            _transactionsDataService.DeleteTransaction(transaction.ID, client.ID);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Serilog.Log.Logger?.Error(ex, "Demo Clean Down Failed with error: {ex.Message}");
            }

            base.Execute(task);
        }
 public bool DeleteTransaction(string transactionId, string clientId)
 {
     if (!string.IsNullOrEmpty(transactionId))
     {
         return(_transactionDataService.DeleteTransaction(transactionId, clientId));
     }
     return(false);
 }
Example #3
0
        private decimal ProcessExternalAccount(ExternalAccount externalAccount, IDatafeedAPI datafeedApi, Account account, out decimal availableBalance)
        {
            string encryptedAccessKey = _datafeedDataService.GetAccessKeyForExternalAccount(externalAccount.Provider, externalAccount.VendorID, Task.ClientID);

            availableBalance = 0;

            if (string.IsNullOrEmpty(externalAccount?.AccountID) || string.IsNullOrEmpty(encryptedAccessKey) || datafeedApi == null)
            {
                return(0);
            }

            List <Transaction> transactions = datafeedApi.GetAccountTransactions(externalAccount.AccountID, encryptedAccessKey, out decimal accountBalance, out availableBalance);

            Log($"Fetched [{transactions.Count}] transactions from provider");

            List <Transaction> sortedTransactions = new List <Transaction>();

            foreach (var transaction in transactions)
            {
                transaction.ClientID    = Task.ClientID;
                transaction.AccountID   = account.ID;
                transaction.AccountName = account?.AccountName ?? "Unknown";
                if (sortedTransactions.Where(t => t.ID == transaction.ID).Count() == 0)
                {
                    sortedTransactions.Add(transaction);
                }
            }

            //Run Algorithms
            sortedTransactions = MerchantAlgorithm(sortedTransactions);
            sortedTransactions = VendorAlgorithm(sortedTransactions);

            // Remove any pending transactions that have now been settled (Pending transaction not supplied by provider anymore indicates that  it has settled under a different transaction id)
            var exitingPendingTransactions = _transactionDataService.GetTransactions(account.ClientID).Where(t => t.Status == Status.PENDING && t.Owner != "User");

            foreach (var transaction in exitingPendingTransactions)
            {
                if (!sortedTransactions.Where(t => t.Status == Status.PENDING).Any(t => t.ID == transaction.ID))
                {
                    _transactionDataService.DeleteTransaction(transaction.ID, transaction.ClientID);
                }
            }

            //Add All sorted transactions
            foreach (Transaction transaction in sortedTransactions)
            {
                bool?imported = _transactionDataService.ImportDatafeedTransaction(transaction);
            }

            return(accountBalance);
        }