public async static void CancelOrderAction(string data)
        {
            OrderBill canceledOder = JsonConvert.DeserializeObject <OrderBill>(data);

            //fetch data products in server
            await ServerDatabase.FetchProductData();

            //xóa orderbill
            DataUpdater.DeleteOrderBillByID(canceledOder.IDOrderBill);

            //update list order+số lượng product cho cửa hàng bị hủy order
            if (Infor.IDStore == canceledOder.IDStore)
            {
                (TabbarStoreManager.GetInstance().Children.ElementAt(1).BindingContext as ProductManagerViewModel).LoadData(true);
                (TabbarStoreManager.GetInstance().Children.ElementAt(2).BindingContext as OrderManagerViewModel).LoadData();
            }

            if (Infor.IDUser == canceledOder.IDUser)
            {
                (TabBarCustomer.GetInstance().Children.ElementAt(3).BindingContext as ListOrdersViewModel).LoadData();
            }

            //update số lượng product cho các user khác (gồm cả user là store bị hủy)
            var ShowStoreVM = ShowStoreView.GetInstance().BindingContext as ShowStoreViewModel;

            if (ShowStoreVM != null && ShowStoreVM.IDStore == canceledOder.IDStore)
            {
                ShowStoreVM.LoadData(true);
            }
        }
        public static void AddProductAction(string data)
        {
            Product product = JsonConvert.DeserializeObject <Product>(data);

            DataUpdater.AddProduct(product);
            //update hết tất cả những user đang ở trong màn hình xem cửa hàng (của cửa hàng update product)
            var ShowStoreVM = ShowStoreView.GetInstance().BindingContext as ShowStoreViewModel;

            if (ShowStoreVM != null && ShowStoreVM.IDStore == product.IDStore)
            {
                ShowStoreVM.LoadData(true);
            }
        }
Ejemplo n.º 3
0
        public async void ShowStore(Store store)
        {
            //TẠO FILTER TRƯỚC CHO STORE
            var    filterView = FilterPopupView.GetInstance();
            double maxPrice   = dataProvider.FindMaxPriceInStore(store.IDStore);
            var    VM         = new FilterPopupViewModel(maxPrice);

            filterView.BindingContext = VM;

            ShowStoreView.Destroy();
            var showStoreView = ShowStoreView.GetInstance();

            showStoreView.BindingContext = new ShowStoreViewModel(store.IDStore);
            await App.Current.MainPage.Navigation.PushAsync(showStoreView, true);
        }
        public static void AnswerFeedbackAction(string data)
        {
            OrderBill order = JsonConvert.DeserializeObject <OrderBill>(data);

            DataUpdater.UpdateOrderBill(order);

            //Update lại cho tất cả user: list feedback của cửa hàng đó nếu họ đang xem
            var ShowStoreVM = ShowStoreView.GetInstance().BindingContext as ShowStoreViewModel;

            if (ShowStoreVM != null && ShowStoreVM.IDStore == order.IDStore)
            {
                ShowStoreVM.LoadData(true);
            }
            //update lại list orders cho user là người mua của order được trả lời feedback
            (TabBarCustomer.GetInstance().Children.ElementAt(3).BindingContext as ListOrdersViewModel).LoadData();
        }
        public static void AddToCartAction(string data)
        {
            List <Product> receivedProducts = JsonConvert.DeserializeObject <List <Product> >(data);

            DataUpdater.UpdateProduct(receivedProducts);
            var showStore = ShowStoreView.GetInstance();

            if (showStore.BindingContext != null)
            {
                (showStore.BindingContext as ShowStoreViewModel).LoadData(true);
            }
            if (receivedProducts[0].IDStore == Infor.IDStore)
            {
                (TabbarStoreManager.GetInstance().Children.ElementAt(1).BindingContext as ProductManagerViewModel).LoadData(false);
            }
        }
Ejemplo n.º 6
0
        public async void Apply()
        {
            using (UserDialogs.Instance.Loading("Applying filter.."))
            {
                bool   isFilter  = IsUse;
                string SortType  = SelectedOrder;
                double FilterMin = -1;
                double FilterMax = -1;

                if (IsFilter)
                {
                    FilterMin = LowPrice;
                    FilterMax = HighPrice;
                }

                var ShowStoreVM = ShowStoreView.GetInstance().BindingContext as ShowStoreViewModel;
                ShowStoreVM.ApplyFilter(isFilter, SortType, FilterMin, FilterMax);
                await PopupNavigation.Instance.PopAllAsync();
            }
        }
        public static void ReturnProductCartAction(string data)
        {
            List <Product> products = JsonConvert.DeserializeObject <List <Product> >(data);

            DataUpdater.UpdateProduct(products[0]);
            products.RemoveAt(0);
            DataUpdater.DeleteProducts(products);
            //Load lại data cho các user đang ở trong cửa hàng đó
            var ShowStoreVM = ShowStoreView.GetInstance().BindingContext as ShowStoreViewModel;

            if (ShowStoreVM != null && ShowStoreVM.IDStore == products[0].IDStore)
            {
                ShowStoreVM.LoadData(true);
            }
            //Load lại list product cho cửa hàng đó
            if (products[0].IDStore == Infor.IDStore)
            {
                (TabbarStoreManager.GetInstance().Children.ElementAt(1).BindingContext as ProductManagerViewModel).LoadData(true);
            }
        }
        public async void AddToCart(object sender, EventArgs e)
        {
            //TEST INTERNET CONNECTTION
            var    httpClient = new HttpClient();
            string x          = "";

            try
            {
                var testInternet = await httpClient.GetStringAsync(ServerDatabase.localhost + "store/getstorebyid/test");

                x = testInternet;
            }
            catch (Exception ex)
            {
                await ShowStoreView.GetInstance().DisplayAlert("Error", "Action fail, check your internet connection and try again!", "OK");

                return;
            }


            var viewmodel = this.BindingContext as ShowStoreViewModel;

            if (viewmodel.CheckNoSelectedProduct())
            {
                MessageService.Show("No product is chosen", 0);
                return;
            }
            User user = DataProvider.GetInstance().GetUserByIDUser(Infor.IDUser);

            if (!user.CheckValidInfor())
            {
                var app = AppDrawer.GetInstance();
                app.DisplayAlert("Error", "Your information is not enough, please update your infor and try again!", "OK");
                return;
            }
            viewmodel.AddToCart();
            viewmodel.updateSelectedProduct();
            CollapseTapped(sender, e);
            MessageService.Show("Add to cart success", 0);
        }