public OFXData LoadData(OFXReader OFXReader) { OFXData data = new OFXData(); OFXBankStatement statement = null; var statements = new List <OFXBankStatement>(); var fs = OFXReader.GetFileData(); using (var reader = new StreamReader(fs, System.Text.Encoding.UTF8)) { string line; while ((line = reader.ReadLine()) != null) { data = ReturnAll(line, "<OFX>", data); data = ReturnAll(line, "<CODE>", data); data = ReturnAll(line, "<SEVERITY>", data); data = ReturnAll(line, "<DTSERVER>", data); data = ReturnAll(line, "<LANGUAGE>", data); data = ReturnAll(line, "<TRNUID>", data); data = ReturnAll(line, "<CURDEF>", data); data = ReturnAll(line, "<BANKID>", data); data = ReturnAll(line, "<ACCTID>", data); data = ReturnAll(line, "<ACCTTYPE>", data); data = ReturnAll(line, "<BALAMT>", data); data = ReturnAll(line, "<DTASOF>", data); statement = ReturnAll(line, "<TRNTYPE>", statement, statements); statement = ReturnAll(line, "<DTPOSTED>", statement, statements); statement = ReturnAll(line, "<TRNAMT>", statement, statements); statement = ReturnAll(line, "<MEMO>", statement, statements); } data.statements = statements; } return(data); }
public IActionResult ImportedRegisters(IFormFile[] files) { if (files == null || files.Length == 0) { return(Content("File(s) not selected")); } var transactions = new OFXReader().ReadTransactionsFromFiles(files); var transactionsOrdered = from row in transactions orderby row.DatePosted select row; var viewModel = _mapper.Map <IEnumerable <TransactionViewModel> >(transactionsOrdered); return(View(viewModel)); }
public void LoaOFCFile() { OFXDataBusiness business = new OFXDataBusiness(); var data = new OFXData(); var fileName = @"OFXFIles\extrato1.ofx"; OFXReader r = new OFXReader(fileName); var _OFXData = business.LoadData(r); Assert.IsTrue(((List <OFXBankStatement>)_OFXData.statements).Count() == 31); }
public IList <OFXBankStatement> LoadStatements(OFXReader OFXReader) { var statements = new List <OFXBankStatement>(); OFXBankStatement statement = null; var fs = OFXReader.GetFileData(); using (var reader = new StreamReader(fs, System.Text.Encoding.UTF8)) { string line; while ((line = reader.ReadLine()) != null) { statement = ReturnAll(line, "<TRNTYPE>", statement, statements); statement = ReturnAll(line, "<DTPOSTED>", statement, statements); statement = ReturnAll(line, "<TRNAMT>", statement, statements); statement = ReturnAll(line, "<MEMO>", statement, statements); } } return(statements); }
public IActionResult Index() { try { var file = Request.Form.Files[0]; var folderName = Path.Combine("Resources", "File"); var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName); if (file.Length > 0) { //var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); //var fullPath = Path.Combine(pathToSave, fileName); //var dbPath = Path.Combine(folderName, fileName); //using (var stream = new FileStream(fullPath, FileMode.Create)) //{ var stream = file.OpenReadStream(); // file.CopyTo(stream); OFXDataBusiness business = new OFXDataBusiness(); OFXReader OFXReader = new OFXReader(stream); var data = business.LoadData(OFXReader); _BankStatementBusiness.Add(new Domain.Enitties.BankStatement() { Active = true, CreatedDate = DateTime.Now, Accttype = data.ACCTTYPE, Balamt = data.BALAMT, Bankid = data.BANKID, Curdef = data.CURDEF, Dtasof = data.DTASOF.OFXFormatteddDate(), Dataserver = data.DTSERVER.OFXFormatteddDate(), Language = data.LANGUAGE, Ofx = data.OFX, Severity = data.SEVERITY, Acctid = data.ACCTID, Trnuid = data.TRNUID, Code = data.CODE, Accountlaunches = data.statements.Select(x => new Accountlaunche() { Active = true, CreatedDate = DateTime.Now, Dtposted = x.DTPOSTED.OFXFormatteddDate(), Memo = x.MEMO, Trnamt = x.TRNAMT, Trntype = x.TRNTYPE }).ToList() }); _BankStatementBusiness.Save(); } //var folderName = Path.Combine("Resources", "Images"); //var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName); //if (file.Length > 0) //{ // var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); // var fullPath = Path.Combine(pathToSave, fileName); // var dbPath = Path.Combine(folderName, fileName); // using (var stream = new FileStream(fullPath, FileMode.Create)) // { // file.CopyTo(stream); // } // return Ok(new { dbPath }); //} //else //{ // return BadRequest(); //} } catch (Exception ex) { return(StatusCode(500, $"Internal server error: {ex}")); } return(Ok()); }