Exemplo n.º 1
0
        private void GetChilden(JToken jto, string parentName, Models.UI.Category parentCategory)
        {
            var name = ((JProperty)(jto)).Name;

            var newC = new Models.UI.Category {
                Name = name, Items = new System.Collections.ObjectModel.ObservableCollection <Models.UI.Category>()
            };

            if (jto.Values().Count() > 0)
            {
                foreach (var jt in jto.Values())
                {
                    var names = ((JProperty)(jt)).Name;
                    Debug.WriteLine(name + ":" + names);

                    var children = new Models.UI.Category {
                        UniqueId = names, Name = names, Items = new System.Collections.ObjectModel.ObservableCollection <Models.UI.Category>()
                    };
                    parentCategory.Items.Add(children);

                    if (jt.Values().Count() > 0)
                    {
                        GetChilden(jt, name, children);
                    }
                }
            }
            else
            {
                Debug.WriteLine(parentName + ":" + name);
                parentCategory.Items.Add(newC);
            }
        }
Exemplo n.º 2
0
        public static ObservableCollection <Models.UI.Category> CreateBreadCrumb(Models.UI.Category selectedCategory, RESTModels.Category.RootObject selectedItem, string root)
        {
            var breadCrumb = new ObservableCollection <Models.UI.Category>();

            selectedItem.ancestors.Reverse();

            for (var i = 1; i < selectedItem.ancestors.Count; i++)
            {
                var item = selectedItem.ancestors[i];

                var ancestor = selectedItem.ancestors[i - 1];


                var itemName = item;

                if (breadCrumb.Any(o => o.UniqueId == ancestor))
                {
                    itemName = itemName.Replace(ancestor + " ", "");
                }

                breadCrumb.Add(new Models.UI.Category {
                    Name = itemName, UniqueId = item, IndexOf = 1
                });
            }
            var breadCrumbCategoryName = root;

            if (selectedItem.ancestors.Count > 1)
            {
                for (var i = 0; i < selectedItem.ancestors.Count(); i++)
                {
                    var ancestor = selectedItem.ancestors[i];
                    if (breadCrumb.Any(o => o.UniqueId == ancestor))
                    {
                        breadCrumbCategoryName = i == selectedItem.ancestors.Count - 1 ? breadCrumbCategoryName.Replace(breadCrumb.Single(o => o.UniqueId == ancestor).Name, "") : breadCrumbCategoryName.Replace(ancestor + " ", "");
                    }
                }

                //BreadCrumbCategoryName = BreadCrumbCategoryName;//;.TrimStart(selectedItem.ancestors[selectedItem.ancestors.Count - 1].ToCharArray());
            }

            breadCrumb.Add(new Models.UI.Category {
                Name = breadCrumbCategoryName, UniqueId = selectedCategory.UniqueId, IndexOf = 1
            });


            return(breadCrumb);
        }
Exemplo n.º 3
0
        private async Task <Models.UI.Category> GetCategories(Models.UI.Category result)
        {
            var error = string.Empty;

            try
            {
                LoadingCounter++;
                var isCached = await _storageService.Exists(Constants.CATEGORIES, new TimeSpan(10, 0, 0, 0));

                if (isCached)
                {
                    result = JsonConvert.DeserializeObject <Models.UI.Category>(await _storageService.ReadData(Constants.CATEGORIES));
                }
                else
                {
                    result = await Broker.GetCategories();

                    _storageService.Save(Constants.CATEGORIES, result.ToString());
                }

                AppBase.Current.LoadedCategories = result;
                LoadingCounter--;
            }
            catch (Exception ex)
            {
                error = string.Format(International.Translation.ErrorGetting, "categories", ex.Message);

                LoadingCounter--;
            }

            if (!string.IsNullOrEmpty(error))
            {
                await _uxService.ShowAlert(error);
            }

            return(result);
        }
Exemplo n.º 4
0
 private Models.UI.Category Recursive(JToken jTk, Models.UI.Category parent)
 {
     return(new Models.UI.Category());
 }
Exemplo n.º 5
0
        public async Task <Models.UI.Category> GetCategories()
        {
            var categories = new Models.UI.Category();


            try
            {
                var url = new StringBuilder();
                url.Append(BaseUrl).Append(Categories);
                RemoveAuthorizationHeader();
                var response = await _client.GetAsync(url.ToString());

                response.EnsureSuccessStatusCode();
                var content = await response.Content.ReadAsStringAsync();

                Debug.WriteLine(content);
                var rootJson = JObject.Parse(content);

                categories.Name  = "root";
                categories.Items = new System.Collections.ObjectModel.ObservableCollection <Models.UI.Category>();

                foreach (var item in rootJson)
                {
                    var itemname  = item.Key;
                    var itemvalue = item.Value;


                    var newC = new Models.UI.Category {
                        Order = RootCategoryOrder(itemname), UniqueId = itemname, Name = itemname, Items = new System.Collections.ObjectModel.ObservableCollection <Models.UI.Category>()
                    };
                    categories.Items.Add(newC);

                    foreach (var jt in item.Value)
                    {
                        var name = ((JProperty)(jt)).Name;
                        Debug.WriteLine(itemname + ":" + name);

                        var children = new Models.UI.Category {
                            UniqueId = name, Name = name, Items = new System.Collections.ObjectModel.ObservableCollection <Models.UI.Category>()
                        };
                        newC.Items.Add(children);
                        if (jt.Values().Count() > 0)
                        {
                            GetChilden(jt, itemname, children);
                        }
                    }
                }
            }
            catch (HttpRequestException hex)
            {
                throw hex;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            var x = categories.Items.OrderBy(o => o.Order);
            var y = new Models.UI.Category();

            foreach (var catOrder in x)
            {
                y.Items.Add(catOrder);
            }

            return(y);
        }