A Dto to persist a single transaction from a statement.
示例#1
0
 partial void ToModelPostprocessing(TransactionDto dto, ref Transaction model)
 {
     model.Account         = this.accountRepo.GetByKey(dto.Account);
     model.BudgetBucket    = this.bucketRepo.GetByCode(dto.BudgetBucketCode);
     model.TransactionType = this.transactionTypeRepo.GetOrCreateNew(dto.TransactionType);
 }
示例#2
0
 partial void ToDtoPostprocessing(ref TransactionDto dto, Transaction model)
 {
     dto.Account          = model.Account.Name;
     dto.BudgetBucketCode = model.BudgetBucket?.Code;
     dto.TransactionType  = model.TransactionType.Name;
 }
        private List<TransactionDto> ReadTransactions(long totalLines, List<string> allLines)
        {
            var transactions = new List<TransactionDto>();
            for (int index = 1; index < totalLines; index++)
            {
                string line = allLines[index];
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                string[] split = line.Split(',');
                TransactionDto transaction;
                try
                {
                    transaction = new TransactionDto
                    {
                        TransactionType = this.importUtilities.SafeArrayFetchString(split, 0),
                        Description = this.importUtilities.SafeArrayFetchString(split, 1),
                        Reference1 = this.importUtilities.SafeArrayFetchString(split, 2),
                        Reference2 = this.importUtilities.SafeArrayFetchString(split, 3),
                        Reference3 = this.importUtilities.SafeArrayFetchString(split, 4),
                        Amount = this.importUtilities.SafeArrayFetchDecimal(split, 5),
                        Date = this.importUtilities.SafeArrayFetchDate(split, 6),
                        BudgetBucketCode = this.importUtilities.SafeArrayFetchString(split, 7),
                        AccountType = this.importUtilities.SafeArrayFetchString(split, 8),
                        Id = this.importUtilities.SafeArrayFetchGuid(split, 9),
                    };
                }
                catch (IndexOutOfRangeException ex)
                {
                    throw new FileFormatException("The Budget Analyser file does not have the correct number of columns.", ex);
                }

                if (transaction.Amount == 0 || transaction.Date == DateTime.MinValue || transaction.Id == Guid.Empty)
                {
                    throw new FileFormatException("The Budget Analyser file does not contain the correct data type for Amount and/or Date and/or Id in row " + index + 1);
                }

                transactions.Add(transaction);
            }

            return transactions;
        }
        private List<TransactionDto> ReadTransactions(long totalLines, List<string> allLines)
        {
            var transactions = new List<TransactionDto>();
            for (var index = 1; index < totalLines; index++)
            {
                var line = allLines[index];
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                string[] split = line.Split(',');
                TransactionDto transaction;
                try
                {
                    transaction = new TransactionDto
                    {
                        TransactionType = this.importUtilities.FetchString(split, 0),
                        Description = this.importUtilities.FetchString(split, 1),
                        Reference1 = this.importUtilities.FetchString(split, 2),
                        Reference2 = this.importUtilities.FetchString(split, 3),
                        Reference3 = this.importUtilities.FetchString(split, 4),
                        Amount = this.importUtilities.FetchDecimal(split, 5),
                        Date = this.importUtilities.FetchDate(split, 6),
                        BudgetBucketCode = this.importUtilities.FetchString(split, 7),
                        Account = this.importUtilities.FetchString(split, 8),
                        Id = this.importUtilities.FetchGuid(split, 9)
                    };
                }
                catch (InvalidDataException ex)
                {
                    throw new DataFormatException("The Budget Analyser is corrupt. The file has some invalid data in inappropriate columns.", ex);
                }
                catch (IndexOutOfRangeException ex)
                {
                    throw new DataFormatException("The Budget Analyser is corrupt. The file does not have the correct number of columns.", ex);
                }

                if (transaction.Date == DateTime.MinValue || transaction.Id == Guid.Empty)
                {
                    // Do not check for Amount == 0 here, sometimes memo transactions can appear with 0.00 or null amounts; which are valid.
                    throw new DataFormatException(
                        "The Budget Analyser file does not contain the correct data type for Date and/or Id in row " +
                        index + 1);
                }

                transactions.Add(transaction);
            }

            return transactions;
        }
 partial void ToModelPostprocessing(TransactionDto dto, ref Transaction model)
 {
     model.Account = this.accountRepo.GetByKey(dto.Account);
     model.BudgetBucket = this.bucketRepo.GetByCode(dto.BudgetBucketCode);
     model.TransactionType = this.transactionTypeRepo.GetOrCreateNew(dto.TransactionType);
 }
 partial void ToDtoPostprocessing(ref TransactionDto dto, Transaction model)
 {
     dto.Account = model.Account.Name;
     dto.BudgetBucketCode = model.BudgetBucket?.Code;
     dto.TransactionType = model.TransactionType.Name;
 }