Exemplo n.º 1
0
        public async Task <ApplicationProductList> GetAllProductsAsync()
        {
            var uri = UriHelper.CombineUri(GlobalSetting.Instance.GatewayShoppingEndpoint, $"{ApiUrlBase}/all");

            ApplicationProductList result = await _requestProvider.GetAsync <ApplicationProductList>(uri);

            _applicationProductList = result;

            if (Beverages != null)
            {
                Beverages.Clear();
                CannedGoods.Clear();
                Cleaners.Clear();
                DryGoods.Clear();
                PaperGoods.Clear();
                PersonalCare.Clear();
                Others.Clear();
            }

            // populate product types
            foreach (var i in result.Items)
            {
                if (i.Type == null)
                {
                    i.Type = "others";
                }

                switch (i.Type.ToLower())
                {
                case "beverage":
                    Beverages.Add(new ProductModel(i));
                    break;

                case "canned goods":
                    CannedGoods.Add(new ProductModel(i));
                    break;

                case "cleaners":
                    Cleaners.Add(new ProductModel(i));
                    break;

                case "dry goods":
                    DryGoods.Add(new ProductModel(i));
                    break;

                case "paper goods":
                    PaperGoods.Add(new ProductModel(i));
                    break;

                case "personal care":
                    PersonalCare.Add(new ProductModel(i));
                    break;

                default:
                    Others.Add(new ProductModel(i));
                    break;
                }
            }

            Beverages    = SortCategory(_beverages);
            CannedGoods  = SortCategory(_cannedGoods);
            Cleaners     = SortCategory(_cleaners);
            DryGoods     = SortCategory(_dryGoods);
            PaperGoods   = SortCategory(_paperGoods);
            PersonalCare = SortCategory(_personalCare);
            Others       = SortCategory(_others);

            return(result);
        }