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 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 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); }