Ejemplo n.º 1
0
        static decimal GetAbsoluteAmount(CsvTransaction csvTransaction, TransactionType transactionType)
        {
            var amount = transactionType == TransactionType.Credit
                ? csvTransaction.Credit : csvTransaction.Debit;

            if (!decimal.TryParse(amount, out var value))
            {
                throw new Exception($"'{amount}' is not a number.");
            }
            return(Math.Abs(value));
        }
Ejemplo n.º 2
0
        static TransactionType GetTransactionType(CsvTransaction transaction)
        {
            var isCredit = !string.IsNullOrEmpty(transaction.Credit);
            var isDebit  = !string.IsNullOrEmpty(transaction.Debit);

            if (isCredit || isDebit)
            {
                if (isCredit && isDebit)
                {
                    throw new Exception($"A transaction can only have either a credit amount or a debit amount");
                }

                if (isCredit)
                {
                    return(TransactionType.Credit);
                }
                return(TransactionType.Debit);
            }
            else
            {
                throw new Exception($"A transaction was found with out a credit or debit amount.");
            }
        }