/* Public Methods. */ public static IEnumerable <DailyOffer> GetDeals(string fileContents, MERCHANT merchant) { var doc = XDocument.Load(fileContents); return(from product in doc.Descendants("prod") where product.Attribute("in_stock").Value == "yes" select new ShopWindowDailyOffer { Language = GetAttribute(product, "lang"), AWThumb = GetChild(product, "awThumb"), MerchantThumbnail = GetChild(product, "mThumb"), MerchantLink = GetChild(product, "mLink"), MerchantImage = GetChild(product, "mImage"), WebOffer = GetAttribute(product, "web_offer"), InStock = GetAttribute(product, "in_stock"), StockQuantity = GetAttribute(product, "stock_quantity"), ProductMerchantId = GetChild(product, "pId"), PreOrder = GetAttribute(product, "pre_order"), BrandName = GetChild(product, "brandName"), Description = GetChild(product, "desc"), Warranty = GetChild(product, "warranty"), Spec = GetChild(product, "spec"), Title = GetChild(product, "name"), ImageUrl = GetChild(product, "awImage"), Merchant = merchant.ToString(), Source = "SHOP_WINDOW", Promo = GetChild(product, "promo"), UniqueId = product.Attribute("id").Value, OfferEndTime = GetChild(product, "valTo"), OfferStartTime = GetChild(product, "valFrom"), BuyNowPrice = GetChild(product, "buynow"), StorePrice = GetChild(product, "store"), RecommendedRetailPrice = GetChild(product, "rrp"), Delivery = GetChild(product, "delivery"), PurchaseUrl = GetChild(product, "awTrack"), Value = GetValue(product), Products = new List <string> { GetChild(product, "awCat").Replace("&", "and") } }); }
public static IEnumerable <DailyOffer> GetDeals(string file, MERCHANT merchant) { var doc = JsonConvert.DeserializeObject <JObject>(File.ReadAllText(file)); var deals = doc["deals"]; foreach (var deal in deals) { var counter = 0; foreach (var option in deal.SelectToken("options")) { var dailyOffer = new AmazonDailyOffer { Title = GetProperty(option, "title"), Description = GetProperty(deal, "description"), ImageUrl = GetProperty(deal, "imageUrl"), FinePrint = GetProperty(deal, "finePrint"), Price = GetProperty(option, "price.amountInBaseUnit"), Value = GetProperty(option, "value.amountInBaseUnit"), Source = merchant.ToString(), UniqueId = GetProperty(deal, "asin") + "/CODE/" + counter, OfferEndTime = new DateTime(long.Parse(GetProperty(deal, "offerEndTime")) / 1000).ToString(), Merchant = GetProperty(deal, "merchant.displayName"), Products = new List <string> { GetProperty(deal, "category.name") }, Geographies = deal.SelectToken("geographies").Select(x => x.SelectToken("displayName").Value <String>()) }; counter++; yield return(dailyOffer); } } }