public int ImportTransactions(Stream stream, string fileExtension)
        {
            IList <TransactionMappingData> transactions = GetTransactionFromFileImport(stream, fileExtension);
            IList <string> messages = new List <string>();
            var            counter  = 0;

            foreach (var transaction in transactions)
            {
                try
                {
                    ITransaction newTransaction = new Transaction
                    {
                        TransactionId = transaction.TransactionId,
                        Amount        = double.Parse(transaction.Amount),
                        Date          = DateTimeUtils.ParseDate(transaction.TransactionDate, fileExtension),
                        Status        = StatusUtils.GetStatusId(transaction.Status.ToLowerInvariant(), fileExtension),
                        CurrencyCode  = CurrencyUtils.GetValidCurrencyCode(_allCurrencyCodes, transaction.CurrencyCode)
                    };

                    _transactionServices.InsertTransaction(newTransaction);

                    counter++;
                }
                catch (Exception ex)
                {
                    var errMessage = $"Error import transaction id: {transaction.TransactionId}, {ex.Message}";
                    _logger.Error(errMessage);
                    messages.Add(errMessage);
                }
            }

            if (messages.Any())
            {
                throw new Exception(string.Join("\r\n", messages.ToArray()));
            }

            return(counter);
        }
Ejemplo n.º 2
0
 public void StatusUtils_CanGetStatusId(string status, string extension, string expected)
 {
     Assert.AreEqual(expected, StatusUtils.GetStatusId(status, extension));
 }