Пример #1
0
        private async Task InitData()
        {
            await Task.Delay(300);

            //Load current currency
            var currentCurrency = await _wooCommerceService.GetCurrentCurrency().ConfigureAwait(false);

            GlobalSettings.CurrentCurrency = currentCurrency ?? new CurrencyModel();
            CurrentCurrency = GlobalSettings.CurrentCurrency;

            await WebRequestExecuter.Execute(async() => await _wooCommerceService.GetCategories(), async (catagories) =>
            {
                if (catagories != null && catagories.Any())
                {
                    CategoryTabItems = new ObservableCollection <TabModel>(catagories.Where(x => x.Parent == 0).Select(x => new TabModel
                                                                                                                       //CategoryTabItems = new ObservableCollection<TabModel>(catagories.Select(x => new TabModel
                    {
                        ItemThreshold = -1,
                        ImageUrl      = x.Image.ImageUrl,
                        Title         = x.Name,
                        CategoryId    = x.Id
                    }));

                    CurrentTab = CategoryTabItems[0];

                    //await Task.Delay(300);
                    if (CategoryId > 0)
                    {
                        var categoriesData = catagories.Where(x => x.Parent == 0).ToList();
                        //var categoriesData = catagories.ToList();
                        var index  = categoriesData.FindIndex(x => x.Id == CategoryId);
                        CurrentTab = CategoryTabItems[index];
                    }

                    foreach (var tab in CategoryTabItems)
                    {
                        await LoadTabData(tab);
                    }
                }
            }, showConnectionError : false);

            UserInfo = GlobalSettings.User;

            bool isGranted = await AppHelpers.RequestPermission(Permission.Location);

            if (isGranted)
            {
                var myPosition = await AppHelpers.GetCurrentPosition();

                if (myPosition != null)
                {
                    try
                    {
                        var placemarks = await Geocoding.GetPlacemarksAsync(myPosition.Latitude, myPosition.Longitude);

                        var place = placemarks.FirstOrDefault();

                        CurrentAddress = $"{place.FeatureName} {place.Thoroughfare ?? place.SubThoroughfare}, {place.SubAdminArea}, {place.AdminArea}";
                    }
                    catch (FeatureNotSupportedException fnsEx)
                    {
                        // Feature not supported on device
                    }
                    catch (Exception ex)
                    {
                        // Handle exception that may have occurred in geocoding
                    }
                }
            }
        }
Пример #2
0
        private async Task InitData()
        {
            CurrentPage = 1;
            await Task.Delay(100);

            await SetBusyAsync(async() =>
            {
                var wordpressCategoryTask = WebRequestExecuter.Execute(async() => await _appService.GetAllCategories(), async(result) =>
                {
                    if (result != null && result.Any())
                    {
                        Categories = GlobalSettings.WpCategories = result.ToList();

                        ShowButton          = false;
                        var slidersTask     = _appService.GetAllPostsByCategory(AppHelpers.GetCategoryId(GlobalSettings.Slug.Slider));
                        var whatNewsTask    = _appService.GetAllPostsByCategory(AppHelpers.GetCategoryId(GlobalSettings.Slug.WhatsNews));
                        var newsTask        = _appService.GetAllPostsByCategory(AppHelpers.GetCategoryId(GlobalSettings.Slug.News));
                        var coffeeLoverTask = _appService.GetAllPostsByCategory(AppHelpers.GetCategoryId(GlobalSettings.Slug.CoffeeLover));
                        await Task.WhenAll(slidersTask, whatNewsTask, newsTask, coffeeLoverTask);

                        // <summary>
                        /// Gets/sets the all Slider posts from WP to Banner slider.
                        /// </summary>
                        //var sliders = await _appService.GetAllPostsByCategory(AppHelpers.GetCategoryId(GlobalSettings.Slug.Slider));
                        var sliders = slidersTask.Result;
                        if (sliders != null)
                        {
                            Sliders = new ObservableCollection <Post>(sliders.ToList());
                            //Sliders = new ObservableCollection<Post>(posts.Result.ToList());
                        }

                        /// <summary>
                        /// Gets/sets the all What's News posts from WP to Horizontal List Layout.
                        /// </summary>
                        //var whatnews = await _appService.GetAllPostsByCategory(AppHelpers.GetCategoryId(GlobalSettings.Slug.WhatsNews));

                        var whatnews = whatNewsTask.Result;
                        if (whatnews != null)
                        {
                            WhatsNews = new ObservableCollection <Post>(whatnews.ToList());
                        }

                        /// <summary>
                        /// Gets/sets the all News posts from WP to Horizontal List Layout.
                        /// </summary>
                        //var news = await _appService.GetAllPostsByCategory(AppHelpers.GetCategoryId(GlobalSettings.Slug.News));

                        var news = newsTask.Result;
                        if (news != null)
                        {
                            News         = new ObservableCollection <Post>(news.ToList());
                            SelectedNews = News.FirstOrDefault();
                        }

                        /// <summary>
                        /// Gets/sets the all Coffee Lover posts from WP to Horizontal List Layout.
                        /// </summary>
                        //var events = await _appService.GetAllPostsByCategory(AppHelpers.GetCategoryId(GlobalSettings.Slug.Events));

                        var coffeeLover = coffeeLoverTask.Result;
                        if (coffeeLover != null)
                        {
                            CoffeeLover         = new ObservableCollection <Post>(coffeeLover.ToList());
                            SelectedCoffeeLover = CoffeeLover.FirstOrDefault();
                        }
                        ShowButton = true;
                    }
                });

                var woocommerceTask = WebRequestExecuter.Execute(async() => await _wooCommerceService.GetCategories(), async(wcCatagories) =>
                {
                    if (wcCatagories != null && wcCatagories.Any())
                    {
                        ProductCategories = new ObservableCollection <CategoryModel>(wcCatagories.Where(x => x.Parent == 0).ToList());
                    }
                }, showConnectionError: false);


                //var featureProductTask = WebRequestExecuter.Execute(async () => await _wooCommerceService.GetAllProducts(CurrentPage, GlobalSettings.AppConst.PageSize), async (allProducts) =>
                //{
                //    if (allProducts != null && allProducts.Any())
                //    {
                //        FeaturedProducts = new ObservableCollection<ProductModel>(allProducts.Where(x => x.Featured == true).ToList());
                //    }
                //}, showConnectionError: false);

                await Task.WhenAll(wordpressCategoryTask, woocommerceTask);
            });
        }