Esempio n. 1
0
        private async Task LoadWhiteWines()
        {
            if (whitewineModelList.Count == 0 || WhiteWineRefreshedNext < DateTime.Now)
            {
                WhiteWineRefreshedNext = DateTime.Now.AddMinutes(40);

                var categories = await DealData.GetDealByWineTypeAsync(false);

                whitewineModelList = new List <DealsInCategoryViewModel>();
                DealsInCategoryViewModel cvm;
                foreach (var item in categories)
                {
                    if (!string.IsNullOrEmpty(item.DealId))
                    {
                        cvm = new DealsInCategoryViewModel();

                        cvm.Title     = item.Title;
                        cvm.Price     = string.Format("{0:C}", item.Price);
                        cvm.DealId    = item.DealId;
                        cvm.WineColor = "#FFDCE08C";

                        whitewineModelList.Add(cvm);
                    }
                }

                WhiteWineDealsGridView.ItemsSource = whitewineModelList;

                foreach (var item in whitewineModelList)
                {
                    var images = await DealImageData.GetDealImagesAsync(item.DealId, "250x250");

                    item.ImageUrls = images.Select(x => x.ImageUrl).First();
                }
            }
        }
        private async Task LoadViewModel()
        {
            if (!vm.Keys.Contains(CategoryIdParam))
            {
                var categories = await DealData.GetDealsAsync(CategoryIdParam);

                viewModel = new List <DealsInCategoryViewModel>();
                DealsInCategoryViewModel cvm;
                foreach (var item in categories)
                {
                    if (!string.IsNullOrEmpty(item.DealId))
                    {
                        cvm = new DealsInCategoryViewModel();

                        if (item.Redwine)
                        {
                            cvm.WineColor = "#FF660E00";
                        }
                        else
                        {
                            cvm.WineColor = "#FFDCE08C";
                        }

                        cvm.Title  = item.Title;
                        cvm.Price  = string.Format("{0:C}", item.Price);
                        cvm.DealId = item.DealId;

                        viewModel.Add(cvm);
                    }
                }

                vm.Add(CategoryIdParam, viewModel);

                var source = vm.Where(e => e.Key == CategoryIdParam).Select(e => e.Value).Single();
                itemsViewSource.Source = source;

                foreach (var item in viewModel)
                {
                    var images = await DealImageData.GetDealImagesAsync(item.DealId, "250x250");

                    item.ImageUrls = images.Select(x => x.ImageUrl).First();
                }
            }
            else
            {
                var source = vm.Where(e => e.Key == CategoryIdParam).Select(e => e.Value).Single();
                itemsViewSource.Source = source;
            }
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            var dealPar = (DealsInCategoryViewModel)e.Parameter;

            pageTitle.Text = dealPar.Title;

            thisDeal = await DealData.GetDealAsync(dealPar.DealId);

            var dealImages = await DealImageData.GetDealImagesAsync(thisDeal.DealId, "250x250");

            imageGrid.ItemsSource = dealImages;

            title.Text       = thisDeal.Title;
            description.Text = thisDeal.Description;
            tblPrice.Text    = string.Format("{0:C}", thisDeal.Price);

            tbBeginDeal.Text = string.Format("{0:d MMM}", thisDeal.BeginDeal) + " - " + string.Format("{0:d MMM}", thisDeal.EndDeal);
        }