public static OfxAccountDTO OfxParse(this string ofxFileData) { XElement root = ofxFileData.OfxParseToXElement(); OfxAccountDTO account = root.OfxTranslateToDTO(); return(account); }
public static OfxAccountDTO OfxTranslateToDTO(this XElement element) { var accountID = element.Element("ACCTID"); var accountType = element.Element("ACCTTYPE"); var bankID = element.Element("BANKID"); var organization = element.Element("ORG"); OfxAccountDTO account = new OfxAccountDTO { Organization = organization != null ? organization.Value : null, AccountID = accountID != null ? accountID.Value : null, AccountType = accountType != null ? accountType.Value : null, BankID = bankID != null ? bankID.Value : null }; account.Transactions = (from c in element.Descendants("STMTTRN") let name = c.Element("NAME") let memo = c.Element("MEMO") select new OfxTransactionDTO { TransactionID = c.Element("FITID").Value, TransactionType = c.Element("TRNTYPE").Value, Date = DateTime.ParseExact( c.Element("DTPOSTED").Value, "yyyyMMdd", null), Amount = decimal.Parse( c.Element("TRNAMT").Value.Replace("-", ""), NumberFormatInfo.InvariantInfo), Name = name != null ? name.Value : null, Memo = memo != null ? memo.Value : null }); return(account); }