static void Main(string[] args) { List <Product> productList = new List <Product>(); Category.CategoryData categoryData = GetProductCategories(); if (categoryData != null) { categoryData.top5category.ForEach(c => { produ products = RequestProductPrice(c.top5category.id.ToString()); productList.AddRange(products); }); if (productList.Any()) { } } }
public static Category.CategoryData GetProductCategories() { Category.CategoryData categoryData = new Category.CategoryData(); var client = new RestClient("http://sandbox.buscape.com/service/findCategoryList/buscape/"); Console.WriteLine("- Requesting Categories"); var request = new RestRequest("{token}/BR/", Method.POST); request.AddParameter("CategoryId", "0"); // adds to POST or URL querystring based on Method request.AddParameter("format", "json"); // adds to POST or URL querystring based on Method request.AddUrlSegment("token", "4f714f6c423865466654413d"); // replaces matching token in request.Resource // execute the request IRestResponse response = client.Execute(request); var content = response.Content; // raw content as string Console.WriteLine("- Processing response..."); categoryData = JsonConvert.DeserializeObject <Category.CategoryData>(content); //JToken token = JObject.Parse(content); //var categories = token.SelectToken("subcategory"); //var top5categories = token.SelectToken("top5category"); //if (top5categories!= null) //{ // Console.WriteLine("- Top5categories received: {0}...", top5categories.Count()); // Console.WriteLine("- Adding Top5Categories to list..."); // foreach (var item in top5categories) // { // var category = item.SelectToken("top5category").ToObject<CategoryData>(); // if (category != null) // { // Console.WriteLine("- Adding category {0}...", category.name); // productCategories.Add(category); // } // } //} //else // Console.WriteLine("- Top5categories received: 0..."); //if (categories != null) //{ // Console.WriteLine("- Categories received: {0}...", categories.Count()); // Console.WriteLine("- Adding Categories to list..."); // foreach (var item in categories) // { // var category = item.SelectToken("subcategory").ToObject<CategoryData>(); // if (category != null && !productCategories.Any(c => c.id == category.id)) // { // Console.WriteLine("- Adding category {0}...", category.name); // productCategories.Add(category); // } // } //} //else // Console.WriteLine("- Categories received: 0..."); return(categoryData); }