Exemplo n.º 1
0
        public async void ReturnProduct(ProductItemCart productItem)
        {
            //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;
            }

            Product product        = productItem.Product;
            Product deletedProduct = dataProvider.GetProductInCartByIDSourceProduct(product.IDSourceProduct);

            DataUpdater.ReturnProductToSourceProduct(deletedProduct);


            Product changedProduct = dataProvider.GetProductByID(product.IDSourceProduct);

            using (UserDialogs.Instance.Loading("wait.."))
            {
                //Update lại product cho server database
                await httpClient.PostAsJsonAsync(ServerDatabase.localhost + "product/update", changedProduct);

                //xóa product bị hủy trong cart
                await httpClient.PostAsJsonAsync(ServerDatabase.localhost + "product/deleteproductbyid/" + deletedProduct.IDProduct, new { });


                //load lại data product cho store được trả về VÀ TRONG CART
                DataUpdater.DeletedProductInCart(deletedProduct);
                LoadData();
            }



            //PUSH NOTI
            List <Product> productForPushNoti = new List <Product>();

            productForPushNoti.Add(changedProduct);
            productForPushNoti.Add(deletedProduct);
            string datas = PushNotificationService.ConvertDataReturnProductCart(productForPushNoti);

            PushNotificationService.Push(NotiNumber.ReturnProductCart, datas, true);
        }