snapalot
9/1/2017 - 11:49 AM

Get WordPress posts from Firebase for parent and child categories (if they exist)

Get WordPress posts from Firebase for parent and child categories (if they exist)

private void DoWork()
        {
            //get the basic configuration
 
            WebClient wc = new WebClient();
            FireSharp.Response.FirebaseResponse configResponse = _client.Get(configPath);
 
            _configJson = configResponse.Body;
            Config = (ConfigVO)Newtonsoft.Json.JsonConvert.DeserializeObject(_configJson, typeof(ConfigVO));
 
            //get the category ids
            foreach (Category cat in Config.categories)
            {
                //get all the child categories
                string catJson = wc.DownloadString($"{Config.url.category}?context=view&parent={cat.wpCatId}");
                List<CategoryVO> childCategories = (List<CategoryVO>)Newtonsoft.Json.JsonConvert.DeserializeObject(catJson, typeof(List<CategoryVO>));
 
                cat.childCategoryIds = childCategories.Count > 0 ? string.Join(",", childCategories.Select(x => x.id)) : cat.wpCatId.ToString();
            }
 
        }