private void GetTransactions(Bank bank) { using (var reader = new StreamReader(Path + TranFile)) { _tranFileCounter = 0; var textfromfile = reader.ReadLine(); while (textfromfile != null) { _tranFileCounter++; var columns = textfromfile.Split(';'); // Check next row textfromfile = reader.ReadLine(); // Ignore the first line if (_tranFileCounter == 1) { continue; } /* How the writeline looks like * sw.WriteLine($"{item.TransactionId};{balance};{amount};" + * $"{item.CustomerId};{from};{to};" + * $"{item.TrnDate};{item.Type}"); */ // Get enum value if (Enum.TryParse(columns[7], out TransactionType type)) { } else { // Throw exception instead? Output.RedColor("Kunde inte omvandla transaktionstypen från filen"); } // Check if value is "" int?fromAcc = null; int?toAcc = null; if (columns[4] != "" && columns[4] != null) { fromAcc = int.Parse(columns[4]); } if (columns[5] != "" && columns[5] != null) { toAcc = int.Parse(columns[5]); } // Check transactions bank.ListOfTransactions.Add(new Transaction() { Id = int.Parse(columns[0]), FromAccountBalance = ConvertStringToDecimalWithDecimal(columns[1]), Amount = ConvertStringToDecimalWithDecimal(columns[2]), FromAccountId = fromAcc, ToAccountId = toAcc, Date = DateTime.Parse(columns[6]), Type = type }); } } Console.WriteLine($"Antal transaktioner: {bank.ListOfTransactions.Count}"); }