Esempio n. 1
0
        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;
                }
            }
        }
Esempio n. 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;
            }
        }
        private async void PopulateViewModel()
        {
            List <DealsTrolleyViewModel> viewModelList = new List <DealsTrolleyViewModel>();

            foreach (var item in App._DealBasket.GetDealsInBasket())
            {
                var viewModel = new DealsTrolleyViewModel();
                viewModel._Deal = await DealData.GetDealAsync(item.DealId);

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

                viewModel.ImageUrl   = image.ImageUrl;
                viewModel.TotalPrice = String.Format("{0:C}", App._DealBasket.BasketTotalPrice);

                viewModelList.Add(viewModel);
            }

            tbPrice.Text           = string.Format("{0:C}", App._DealBasket.BasketTotalPrice);
            itemsViewSource.Source = viewModelList;
        }