public async Task LoadFeaturedAsync() { try { WeakReferenceMessenger.Default.Send(new PageLoadingMessage(true)); var featured = await FSApi.GetHomePageFeaturedAsync(Windows.ApplicationModel.Package.Current.Id.Version.ToVersion()); CarouselItems.CollectionChanged += CarouselItems_CollectionChanged; CarouselItems.Clear(); for (int i = 0; i < featured.Carousel.Count; i++) { try { Urn packageUrn = Urn.Parse(featured.Carousel[i]); var package = await PackageService.GetPackageAsync(packageUrn); CarouselItems.Add(new PackageViewModel(package)); if (i == 0) { SelectedCarouselItemIndex = i; } } catch (System.Exception ex) { var logger = Ioc.Default.GetRequiredService <LoggerService>(); logger.Warn(ex, ex.Message); } } CarouselItems.CollectionChanged -= CarouselItems_CollectionChanged; // Load featured packages from other sources FeaturedPackages = new ObservableCollection <HandlerPackageListPair>(); await foreach (HandlerPackageListPair pair in PackageService.GetFeaturedPackagesAsync()) { FeaturedPackages.Add(pair); } } catch (Flurl.Http.FlurlHttpException ex) { NavService.ShowHttpErrorPage(ex); } catch (System.Exception ex) { var logger = Ioc.Default.GetRequiredService <LoggerService>(); logger.Warn(ex, ex.Message); } WeakReferenceMessenger.Default.Send(new PageLoadingMessage(false)); }
public async Task LoadFeaturedAsync() { var culture = CultureInfo.CurrentUICulture; var region = new RegionInfo(culture.LCID); var featured = await FSApi.GetHomePageFeaturedAsync(); CarouselItems.Clear(); for (int i = 0; i < featured.Carousel.Count; i++) { string productId = featured.Carousel[i]; var product = (await StorefrontApi.GetProduct(productId, region.TwoLetterISORegionName, culture.Name)) .Convert <ProductDetails>().Payload; CarouselItems.Add(new ProductDetailsViewModel(product)); if (i == 0 || (i == 1 && featured.Carousel.Count >= 3)) { SelectedCarouselItemIndex = i; } } }