public string InsertTransaction(Transaction transaction)
        {
            // Force transaction id to be empty
            transaction.ID = Guid.NewGuid().ToString();
            if (string.IsNullOrEmpty(transaction.ClientID))
            {
                return(null);
            }

            if (new AccountProcessor(_connectionString).GetAccountById(transaction.AccountID, transaction.ClientID) == null)
            {
                throw new Exception("Account does not exist");
            }

            transaction.Owner = "User";
            transaction       = _logoCalculator.RunForTransaction(transaction);

            string result = _transactionDataService.InsertTransaction(transaction) ? transaction.ID : null;

            // Run logo calculator task on affected account
            Task logoTask = new Task($"Logo Calculator [{transaction.AccountName}]", transaction.ClientID, TaskType.LogoCalculator, DateTime.Now)
            {
                Data = new Dictionary <string, object> {
                    { "ClientID", transaction.ClientID }, { "AccountID", transaction.AccountID }
                }
            };

            BackgroundJob.Enqueue <LogoCalculatorTask>(t => t.Execute(logoTask));

            return(result);
        }
示例#2
0
 private void BalanceAccount(Account account, decimal accountBalance)
 {
     if (accountBalance != 0 && account.CurrentBalance.HasValue && account.CurrentBalance != accountBalance)
     {
         decimal            difference         = Math.Abs(account.CurrentBalance.Value - accountBalance);
         List <Transaction> recentTransactions = _transactionDataService.GetTransactions(Task.ClientID).Where(t => t.Date > DateTime.Now.AddMonths(-1)).ToList();
         List <Transaction> adjusts            = recentTransactions.Where(t => t.Merchant == "Adjustment Transaction" && t.Type == "Adjust" && t.Amount == (account.CurrentBalance <= accountBalance ? -difference : difference)).ToList();
         Transaction        transaction        = new Transaction(Guid.NewGuid().ToString(), DateTime.Now, account.ID, "Adjust", account.CurrentBalance > accountBalance ? -difference : difference, "Adjust", "Adjustment Transaction", "Adjust", "This transaction is created from an account refresh to ensure that the account is balanced to the provider");
         transaction.ClientID = Task.ClientID;
         transaction.Owner    = nameof(AccountRefresh);
         Log($"Account [{account.AccountName}] is out of balance. Creating adjustment of amount [{transaction.Amount}]");
         _transactionDataService.InsertTransaction(transaction);
     }
 }