public async void DeleteOrder(OrderBill orderBill)
        {
            //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 App.Current.MainPage.DisplayAlert("Error", "Action fail, check your internet connection and try again!", "OK");

                return;
            }

            using (UserDialogs.Instance.Loading("Canceling order"))
            {
                List <Product> productInOrder = dataProvider.GetProductsInBillByIDBill(orderBill.IDOrderBill);
                //update quantityinventory ở local
                List <Product> sourceProducts = DataUpdater.ReturnListProductToSource(productInOrder);
                //api update quantityinventory ở server
                foreach (Product product in sourceProducts)
                {
                    await httpClient.PostAsJsonAsync(ServerDatabase.localhost + "product/update", product);
                }

                //api delete products trong order bị xóa (ở server)
                await httpClient.PostAsJsonAsync(ServerDatabase.localhost + "product/deletebyidorderbill/" + orderBill.IDOrderBill, new { });

                //delete product ở local
                DataUpdater.DeleteProducts(productInOrder);

                //delete orderbill server
                await httpClient.PostAsJsonAsync(ServerDatabase.localhost + "orderbill/deleteorderbillbyid/" + orderBill.IDOrderBill, new { });

                //delete orderbill local
                DataUpdater.DeleteOrderBillByID(orderBill.IDOrderBill);


                //reload ListOrdersView
                LoadData();
            }

            MessageService.Show("Cancel order successfully", 0);

            //PUSH NOTI
            string datas = PushNotificationService.ConvertDataCancelOrder(orderBill);

            PushNotificationService.Push(NotiNumber.CancelOrderForStore, datas, false);
            PushNotificationService.Push(NotiNumber.CancelOrderForOther, datas, true);
        }
        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);
            }
        }
예제 #3
0
        public async void CancelOrder(OrderBill orderBill)
        {
            using (UserDialogs.Instance.Loading("Canceling order"))
            {
                var            httpClient     = new HttpClient();
                List <Product> productInOrder = dataProvider.GetProductsInBillByIDBill(orderBill.IDOrderBill);
                //update quantityinventory ở local
                List <Product> sourceProducts = DataUpdater.ReturnListProductToSource(productInOrder);
                //api update quantityinventory ở server
                foreach (Product product in sourceProducts)
                {
                    await httpClient.PostAsJsonAsync(ServerDatabase.localhost + "product/update", product);
                }

                //api delete products trong order bị xóa (ở server)
                await httpClient.PostAsJsonAsync(ServerDatabase.localhost + "product/deletebyidorderbill/" + orderBill.IDOrderBill, new { });

                //delete product ở local
                DataUpdater.DeleteProducts(productInOrder);

                //delete orderbill server
                await httpClient.PostAsJsonAsync(ServerDatabase.localhost + "orderbill/deleteorderbillbyid/" + orderBill.IDOrderBill, new { });

                //delete orderbill local
                DataUpdater.DeleteOrderBillByID(orderBill.IDOrderBill);

                //Reload data OrderManager
                LoadData();
                //Reload data ProductManager
                (TabbarStoreManager.GetInstance().Children.ElementAt(1).BindingContext as ProductManagerViewModel).LoadData(true);
            }
            MessageService.Show("Cancel order successfully", 0);

            //PUSH NOTI
            string datas = PushNotificationService.ConvertDataCancelOrder(orderBill);

            PushNotificationService.Push(NotiNumber.CancelOrderForCustomer, datas, false);
            PushNotificationService.Push(NotiNumber.CancelOrderForOther, datas, true);
        }