public static PricingDetails Map(string isbnNumber, XDocument document, PricingDetails pricingDetails = null) { if (pricingDetails == null) { pricingDetails = new PricingDetails {IsbnNumber = isbnNumber}; } try { string json = JsonConvert.SerializeXNode(document.Descendants("return").FirstOrDefault()); var jObject = JObject.Parse(json); decimal price = jObject["return"]["listPrice"].Value<decimal>(); string symbol = jObject["return"]["currency"]["symbol"].Value<string>(); pricingDetails.CurrencyDetails.Add(new PricingCurrencyDetails { Currency = symbol, Value = price, }); } catch (Exception) { } return pricingDetails; }
protected void ImportClick(object sender, EventArgs e) { string[] isbnNumbers = LoadIsbnNumbers().ToArray(); WipePriceDatabase(); var collection = PriceHarvestRepository.MongoCollection(); foreach (string isbnNumber in isbnNumbers) { var pricingService = new PricingService(new ConsoleLog()); var pricingDetails = new PricingDetails() { IsbnNumber = isbnNumber }; foreach (Currency currency in pricingService.Currencies) { var price = pricingService.FindPriceByIsbn(isbnNumber, currency); PricingMapper.Map(isbnNumber, price, pricingDetails); } collection.Insert(pricingDetails); } }
private static PricingCurrencyDetails SelectCurrency(PricingDetails pricingDetails, string currency) { var result = pricingDetails.CurrencyDetails.FirstOrDefault(a => a.Currency == currency); if (result == null) { result = pricingDetails.CurrencyDetails.FirstOrDefault(a => a.Currency == "£"); } return result; }