Beispiel #1
0
        //public static List<Category> GetCategoriesByID(int id)
        //{
        //	string advancedFilter = string.Format(AdvancedFiltersList.CategoriesToParentID, id);
        //	string expandList = ExpandList.CategoriesDescription;
        //	string url = WebRequestUtils.GetUrl (Constants.UrlCategories, expandList, advancedFilter);

        //	List<string> jsonsList = WebRequestUtils.GetJsonsAllPage (url);
        //	List<Category> categoriesList = new List<Category>();

        //	if (jsonsList != null)
        //		foreach (var item in jsonsList) {
        //			categoriesList.AddRange (JsonConvert.DeserializeObject<List<Category>> (item));
        //		}
        //	return categoriesList;
        //}

        public static async Task <List <Category> > GetCategoriesByIDAsync(int id, bool isChildren = false)
        {
            string advancedFilter = string.Format(AdvancedFiltersList.CategoriesToParentID, id);
            string expandList     = ExpandList.CategoriesDescription;

            if (isChildren)
            {
                expandList += "," + ExpandList.CategoriesChildren;
            }
            string url = WebRequestUtils.GetUrl(Constants.UrlCategories, expandList, advancedFilter);

            ContentAndHeads contentAndHeads = await WebRequestUtils.GetJsonsAndHeadsAllPageAsync(url);

            List <string>   jsonsList      = contentAndHeads.Content;
            List <Category> categoriesList = new List <Category>();

            if (jsonsList != null)
            {
                foreach (var item in jsonsList)
                {
                    categoriesList.AddRange(JsonConvert.DeserializeObject <List <Category> > (item));
                }
            }
            foreach (var cat in categoriesList)
            {
                cat.Children.RemoveAll(g => g.Status == 0);
            }
            return(categoriesList);
        }
Beispiel #2
0
        public static async Task GetTreeCategoriesAsync(Category category, List <int> categoriesIDList, CancellationTokenSource _cancellationTokenSource)
        {
            if (!category.Children.Any(g => g.Children != null))
            {
                string advancedFilter = string.Format(AdvancedFiltersList.CategoriesToParentID, category.ID);
                string expandList     = ExpandList.CategoriesDescription + "," + ExpandList.CategoriesChildren;
                string url            = WebRequestUtils.GetUrl(Constants.UrlCategories, expandList, advancedFilter);

                ContentAndHeads contentAndHeads = await WebRequestUtils.GetJsonsAndHeadsAllPageAsync(url);

                if (contentAndHeads == null)
                {
                    return;
                }

                List <string> jsonsList = contentAndHeads.Content;
                category.Children = new List <Category>();

                foreach (string item in jsonsList)
                {
                    List <Category> items = JsonConvert.DeserializeObject <List <Category> >(item);
                    category.Children.AddRange(items);
                }
                foreach (var cat in category.Children)
                {
                    cat.Children.RemoveAll(g => g.Status == 0);
                }
            }
            foreach (Category categoryItem in category.Children)
            {
                categoriesIDList.Add(categoryItem.ID);
            }
            foreach (Category cat in category.Children)
            {
                if (_cancellationTokenSource != null && _cancellationTokenSource.IsCancellationRequested)
                {
                    //_cancellationTokenSource = new CancellationTokenSource ();
                    return;
                }
                if (cat.Children != null && cat.Children.Count != 0)
                {
                    await GetTreeCategoriesAsync(cat, categoriesIDList, _cancellationTokenSource);
                }
            }
        }
Beispiel #3
0
        public static async Task <List <Zone> > GetZoneAndCountry()
        {
            string expandList = ExpandList.ZoneCountry;
            string url        = WebRequestUtils.GetUrl(Constants.PathToZone, expandList, null);

            ContentAndHeads contentAndHeads = await WebRequestUtils.GetJsonsAndHeadsAllPageAsync(url);

            List <Zone> zoneList = new List <Zone> ();

            if (contentAndHeads.Content != null)
            {
                foreach (string json in contentAndHeads.Content)
                {
                    zoneList.AddRange(JsonConvert.DeserializeObject <List <Zone> > (json));
                }
            }
            return(zoneList);
        }