public IList <BetEasyModel> Transform(FileInfo file) { IList <BetEasyModel> modelList = new List <BetEasyModel>(); using (StreamReader r = new StreamReader(file.FullName)) { var json = r.ReadToEnd(); JSONModel jsonModel = JsonConvert.DeserializeObject <JSONModel>(json); if (jsonModel != null && jsonModel.RawData != null && jsonModel.RawData.Markets != null) { List <Market> markets = jsonModel.RawData.Markets; foreach (var market in markets) { var selections = market.Selections.Select(t => new { t.Price, t.Tags.name, t.Id }).ToList(); foreach (var selection in selections) { BetEasyModel model = new BetEasyModel(); model.HorseName = selection.name; model.Price = selection.Price; model.Id = selection.Id; modelList.Add(model); } } } } return(modelList); }
public IList <BetEasyModel> Transform(FileInfo file) { IList <BetEasyModel> betEasyModelList = new List <BetEasyModel>(); using (StreamReader r = new StreamReader(file.FullName)) { var xmlData = r.ReadToEnd(); XmlDocument doc = new XmlDocument(); doc.LoadXml(xmlData); XmlNode root = doc.DocumentElement; //Display the contents of the child nodes. XmlNodeList horseNodeList = root.SelectNodes("races/race/horses/horse"); XmlNodeList priceNodeList = root.SelectNodes("races/race/prices/price/horses/horse"); foreach (XmlNode horseNode in horseNodeList) { BetEasyModel model = new BetEasyModel(); model.Id = horseNode.SelectSingleNode("number").InnerText; model.HorseName = horseNode.Attributes["name"].Value; foreach (XmlNode priceNode in priceNodeList) { if (priceNode.Attributes["number"].Value == model.Id) { string price = priceNode.Attributes["Price"].Value; model.Price = double.Parse(price); } } betEasyModelList.Add(model); } } return(betEasyModelList); }