private async void RefreshData()
        {
            var api     = new ArgosAPI();
            var results = await api.Search(ViewModel.Query);

            if (results == null || results.Count == 0)
            {
                stackNoResults.Visibility = Visibility.Visible;
                lstResults.Visibility     = Visibility.Collapsed;
                return;
            }

            stackNoResults.Visibility = Visibility.Collapsed;
            lstResults.Visibility     = Visibility.Visible;

            var index = 0;

            foreach (var result in results)
            {
                var model = new SearchResultViewModel(result)
                {
                    Index = index++
                };

                ViewModel.Results.Add(model);
            }
        }
        private async void RefreshReviews()
        {
            var api    = new ArgosAPI();
            var result = await api.GetReviews(ProductId);


            if (result == null || result.Results == null || result.Results.Count == 0)
            {
                lstReviews.Visibility = Visibility.Collapsed;
                return;
            }

            var index = 0;

            foreach (var x in result.Results)
            {
                var model = new ReviewViewModel()
                {
                    Text          = x.ReviewText,
                    RatingNumeric = x.Rating,
                    Title         = x.Title,
                    UserName      = x.UserNickname,
                    UserLocation  = x.UserLocation,
                    ReviewDate    = x.SubmissionTime,
                    IsRecommended = x.IsRecommended,
                    Index         = index++
                };

                ViewModel.Reviews.Add(model);
            }
        }
        private async void RefreshProductData()
        {
            try
            {
                var api    = new ArgosAPI();
                var result = await api.GetProductDetails(ProductId);

                if (result == null)
                {
                    MessageBox.Show("Unable to find product with the id " + ProductId, "error finding product", MessageBoxButton.OK);
                    if (NavigationService.CanGoBack)
                    {
                        NavigationService.GoBack();
                    }
                    return;
                }

                ViewModel.Description     = result.Description;
                ViewModel.Title           = result.Title;
                ViewModel.PreviewImageUrl = result.PreviewImageUrl;
                ViewModel.Id                = result.Id;
                ViewModel.PriceFormatted    = result.PriceFormatted;
                ViewModel.WasPriceFormatted = result.WasPriceFormatted;
                ViewModel.Promotions        = result.Promotions;

                var image = result.Images.FirstOrDefault(x => x.Type == "largeImage");
                if (image != null)
                {
                    ViewModel.LargeImageUrl = image.Url;
                }

                if (result.Images.Any(x => x.Type == "video"))
                {
                    ViewModel.Videos = result.Images.Where(x => x.Type == "video" && x.Application == "video/mp4").Select(x =>
                                                                                                                          new VideoThumbnail()
                    {
                        Thumbnail = image.Url,
                        Url       = x.Url
                    }).ToList();
                }

                if (result.Images.Any(x => x.Type == "image"))
                {
                    ViewModel.ProductImages = result.Images.Where(x => x.Type == "image").Select(x => x.Url).ToList();
                }

                var rh = new RecentHelper();
                rh.AddRecentItem(ViewModel);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Example #4
0
        private async void RefreshLocation()
        {
            Geolocator geolocator = new Geolocator();

            geolocator.DesiredAccuracyInMeters = 100;

            try
            {
                Geoposition geoposition = await geolocator.GetGeopositionAsync(
                    maximumAge : TimeSpan.FromSeconds(60),
                    timeout : TimeSpan.FromSeconds(10)
                    );

                var latitude  = geoposition.Coordinate.Latitude;
                var longitude = geoposition.Coordinate.Longitude;

                var api    = new ArgosAPI();
                var result = await api.GetStores(longitude, latitude);

                radListStores.DataContext = result;

                var settingsHelper = new SettingsHelper();
                settingsHelper.SaveStores(result);

                var currentApp = ((IArgosApp)(App.Current));

                currentApp.StoresChanged();
            }
            catch (Exception ex)
            {
                if ((uint)ex.HResult == 0x80004004)
                {
                    // todo: say blocked
                    stackNoLocation.Visibility = Visibility.Visible;
                    radListStores.Visibility   = Visibility.Collapsed;
                }
                else
                {
                    // something else happened acquring the location
                }
            }
        }
        private async void RefreshStoreData()
        {
            var settingsHelper = new SettingsHelper();
            var stores         = settingsHelper.GetStores();

            if (stores == null)
            {
                ((IArgosApp)(App.Current)).StoresChangedEvent += (sender, args) => RefreshStoreData();
                return;
            }

            var api = new ArgosAPI();

            var index = 0;

            foreach (var store in stores)
            {
                var result = await api.CheckProductStock(store.Id, ProductId);

                var stockInfo = new StockInfo(store, result);
                stockInfo.Index = index++;
                ViewModel.StockInfo.Add(stockInfo);
            }
        }