private async Task LoadViewModel()
        {
            if (viewModelList == null || RefreshedNext < DateTime.Now)
            {
                RefreshedNext = DateTime.Now.AddMinutes(40);

                var categories = await CategoriesData.GetCategoriesAsync();

                CategoryViewModel cvm;
                foreach (var item in categories)
                {
                    if (!string.IsNullOrEmpty(item.LatestDealId))
                    {
                        cvm = new CategoryViewModel();
                        cvm.CategoryName = item.Name;
                        cvm.LatestDealId = item.LatestDealId;
                        cvm.CategoryId   = item.CategoryId;

                        viewModelList.Add(cvm);
                    }
                }

                itemsViewSource.Source = viewModelList;

                foreach (var item in viewModelList)
                {
                    item.DealCountInCategory = await DealData.GetDealCount(item.CategoryId);

                    var image = await DealImageData.GetDealImageAsync(item.LatestDealId, "250x250");

                    item.LatestImageUrl = image.ImageUrl;
                }
            }
        }
Example #2
0
        private async Task LoadCategories()
        {
            if (!countryCache.Keys.Contains(CountryIdParam) || RefreshedNext < DateTime.Now)
            {
                RefreshedNext = DateTime.Now.AddMinutes(40);

                var categories = await CategoriesData.GetCategoriesAsync();

                viewModelList = new List <CategoryViewModel>();
                CategoryViewModel cvm;
                foreach (var item in categories)
                {
                    if (!string.IsNullOrEmpty(item.LatestDealId))
                    {
                        cvm = new CategoryViewModel();
                        cvm.CategoryName = item.Name;
                        cvm.LatestDealId = item.LatestDealId;
                        cvm.CategoryId   = item.CategoryId;

                        viewModelList.Add(cvm);
                    }
                }

                countryCache.Add(CountryIdParam, viewModelList);
                var source = countryCache.Where(e => e.Key == CountryIdParam).Select(e => e.Value).Single();

                categoryGridView.ItemsSource = source;

                foreach (var item in source)
                {
                    item.DealCountInCategory = await DealData.GetDealCount(CountryIdParam, item.CategoryId);

                    var image = await DealImageData.GetDealImageAsync(item.LatestDealId, "250x250");

                    item.LatestImageUrl = image.ImageUrl;
                }
            }
            else
            {
                var source = countryCache.Where(e => e.Key == CountryIdParam).Select(e => e.Value).Single();
                categoryGridView.ItemsSource = source;
            }
        }