Exemple #1
0
        public void AddTransaction(OFXTransactionModel newData)
        {
            var transaction = _context.OFXTransactionModels.FirstOrDefault(x => x.TransactiontType == newData.TransactiontType &&
                                                                           x.PostedDate == newData.PostedDate &&
                                                                           x.Description == newData.Description);

            if (transaction == null)
            {
                _context.OFXTransactionModels.Add(newData);
                _context.SaveChanges();
            }
        }
Exemple #2
0
        public List <OFXTransactionModel> ReadOFXFileTransactions(string filePath)
        {
            string str = null;
            List <OFXTransactionModel> transactions = new List <OFXTransactionModel>();
            List <string> registers = new List <string>();

            if (File.Exists(filePath))
            {
                Stream       stream       = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                StreamReader streamReader = new StreamReader(stream);
                str = streamReader.ReadToEnd();
                streamReader.Close();
                stream.Close();
            }

            RegexOptions options = RegexOptions.Multiline;

            foreach (Match m in Regex.Matches(str, pattern, options))
            {
                registers.Add(m.Value);
            }

            foreach (var reg in registers)
            {
                OFXTransactionModel transaction = new OFXTransactionModel();
                transaction.TransactiontType = Regex.Matches(reg, transactionTypePattern, options)[0].Value.Split(">")[1].Replace(System.Environment.NewLine, "");
                var date = Regex.Matches(reg, postedDatePattern, options)[0].Value.Split(">")[1].Split("[")[0].Replace(System.Environment.NewLine, "");
                transaction.TransactionAmount = Regex.Matches(reg, transactionAmountPattern, options)[0].Value.Split(">")[1].Replace(System.Environment.NewLine, "");
                transaction.Description       = Regex.Matches(reg, descriptionPattern, options)[0].Value.Split(">")[1].Replace("\'n", "").Replace(System.Environment.NewLine, "");

                string textDate = date.Substring(6, 2) + "/" + date.Substring(4, 2) + "/" + date.Substring(0, 4);

                transaction.PostedDate = DateTime.ParseExact(textDate, "dd/MM/yyyy", null);
                transactions.Add(transaction);
            }

            return(transactions);
        }