/// <summary> /// Convert xml string with transactions detail to object /// </summary> /// <param name="xmlString">xml string for payment or bill</param> /// <param name="nodeName">could be "Payment" or "Bill" </param> /// <returns>List of transaction detail objects</returns> IList <TransactionDetailReportList> ParseTransactionDetails(string xmlString, string nodeName) { var details = new List <TransactionDetailReportList>(); var nodes = _xmlService.GetXMLElements(nodeName, xmlString); string transDetId; string billId; string catId; string subCatId; string amount; string category; string subcategory; string datedue; string quantity; string unitPrice; string cardCharged; string classId; string subclassId; var culturePointer = CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator; foreach (XmlElement node in nodes) { transDetId = CheckXmlValue(_xmlService.GetTransactionDetailsIds(node.OuterXml)); billId = CheckXmlValue(_xmlService.GetBillIDs(node.OuterXml)); catId = CheckXmlValue(_xmlService.GetCategoryID(node.OuterXml)); classId = CheckXmlValue(_xmlService.GetClassId(node.OuterXml)); subclassId = CheckXmlValue(_xmlService.GetSubclassId(node.OuterXml)); subCatId = CheckXmlValue(_xmlService.GetSubcategoryID(node.OuterXml)); amount = CheckXmlValue(_xmlService.GetAmount(node.OuterXml)); category = CheckXmlValue(_xmlService.GetCategory(node.OuterXml)); subcategory = CheckXmlValue(_xmlService.GetSubcategory(node.OuterXml)); datedue = CheckXmlValue(_xmlService.GetDateDue(node.OuterXml)); quantity = CheckXmlValue(_xmlService.GetQuantity(node.OuterXml)); unitPrice = CheckXmlValue(_xmlService.GetUnitPrice(node.OuterXml)); cardCharged = CheckXmlValue(_xmlService.GetCardCharged(node.OuterXml)); var det = new TransactionDetailReportList(); det.TransactionDetailID = string.IsNullOrEmpty(transDetId) ? default(int?) : Convert.ToInt32(transDetId); det.BillID = string.IsNullOrEmpty(billId) ? default(int?) : Convert.ToInt32(billId); det.CategoryID = string.IsNullOrEmpty(catId) ? default(int?) : Convert.ToInt32(catId); det.SubcategoryID = string.IsNullOrEmpty(subCatId) ? default(int?) : Convert.ToInt32(subCatId); det.Amount = string.IsNullOrEmpty(amount) ? default(decimal) : decimal.Parse(amount.Replace(",", culturePointer), CultureInfo.InvariantCulture); det.Category = category; det.Subcategory = subcategory; det.ClassID = string.IsNullOrEmpty(classId) ? default(int?) : Convert.ToInt32(classId); det.SubclassID = string.IsNullOrEmpty(subclassId) ? default(int?) : Convert.ToInt32(subclassId); det.TransType = string.Equals(nodeName, "Payment") ? 1 : 2; if (nodeName == "Bill") { det.DateDue = string.IsNullOrEmpty(datedue) ? default(DateTime?) : DateTime.Parse(datedue); det.Quantity = string.IsNullOrEmpty(quantity) ? default(int?) : Convert.ToInt32(quantity); det.UnitPrice = string.IsNullOrEmpty(unitPrice) ? default(decimal?) : decimal.Parse(unitPrice.Replace(",", culturePointer), CultureInfo.InvariantCulture); det.CardCharged = string.IsNullOrEmpty(cardCharged) ? default(bool?) : string.Equals(cardCharged, "1"); } details.Add(det); } return(details); }