Exemple #1
0
        async void getData(bool from = false, string msg = null)
        {
            try
            {
                System.Diagnostics.Debug.WriteLine("MTG - Home GetData()");
                if (!CrossConnectivity.Current.IsConnected)
                {
                    await DisplayAlert("Alert", "Your device is not connected to internet. Please try again later.",
                                       "Ok");
                }
                else
                {
                    if (from)
                    {
                        Config.ShowDialog();
                    }
                    var response = await CategoryLogic.CategoryList();

                    if (response.status == "200")
                    {
                        //HomeVM.MyFavCounter = response.fav_count;
                        //HomeVM.MyCartCounter = response.cart_count;
                        //MessagingCenter.Send((App)Application.Current, "NavigationBar", "");
                        mainContent.IsVisible  = true;
                        emptyContent.IsVisible = false;
                        if (response.data != null)
                        {
                            itemCategoryList.FlowItemsSource = response.data.ToList();
                        }
                        //headingTitle.IsVisible = true;
                        myView.ItemsSource       = response.sliders;
                        myView.Position          = 0;
                        myView.InterPageSpacing  = 10;
                        myView.AnimateTransition = true;
                        myView.Orientation       = CarouselViewOrientation.Horizontal;

                        if (response.featured != null && response.featured.Count > 0)
                        {
                            featuredLabel.IsVisible      = true;
                            ViewModel.Featureds          = new ObservableCollection <Product>(response.featured.ToList());
                            featuredProducts.ItemsSource = response.featured.ToList();
                        }
                        if (response.quick_products != null && response.quick_products.Count > 0)
                        {
                            quickLabel.IsVisible      = true;
                            ViewModel.Quicks          = new ObservableCollection <Product>(response.quick_products.ToList());
                            quickProducts.ItemsSource = response.quick_products.ToList();
                        }
                        if (response.offered_products != null && response.offered_products.Count > 0)
                        {
                            offeredLabel.IsVisible      = true;
                            ViewModel.Offered           = new ObservableCollection <Product>(response.offered_products.ToList());
                            offeredProducts.ItemsSource = response.offered_products.ToList();
                        }

                        Device.StartTimer(TimeSpan.FromSeconds(5), () =>
                        {
                            SlidePosition++;
                            if (SlidePosition == response.sliders.Count)
                            {
                                SlidePosition = 0;
                            }
                            myView.Position = SlidePosition;
                            return(true);
                        });
                        categoryLabel.IsVisible = true;
                        mainContent.IsVisible   = true;
                        IsBusy.IsVisible        = false;
                    }
                    else
                    {
                        mainContent.IsVisible = true;
                        IsBusy.IsVisible      = false;
                        await DisplayAlert("Alert", response.message, "Ok");
                    }
                    if (from)
                    {
                        Config.HideDialog();
                        if (msg != null)
                        {
                            Config.SnackbarMessage(msg);
                        }
                    }
                }
                if (from)
                {
                    Config.HideDialog();
                }
            }
            catch (Exception ex)
            {
                mainContent.IsVisible = true;
                IsBusy.IsVisible      = false;
                Config.ErrorStore("Home-getData", ex.Message);
                Config.HideDialog();
                await DisplayAlert("Alert", Config.ApiErrorMessage, "Ok");
            }
        }