示例#1
0
        public async Task<bool> UpdateProduct(Product product, StorageFile media)
        {
            try
            {
                if (Utilities.Helpers.NetworkHelper.Instance.HasInternetConnection)
                {
                    if (product.Image == null || product.Image == "/Assets/LockScreenLogo.scale-200.png")
                    {
                        if (media == null)
                            product.Image = "/Assets/LockScreenLogo.scale-200.png";
                        else
                            product.Image = null;
                    }
                    JToken data = JToken.FromObject(product);
                    JToken result = await App.MobileService.InvokeApiAsync("Products", data, HttpMethod.Put, null);
                    JObject response = JObject.Parse(result.ToString());

                    SelectedProduct = response.ToObject<Product>();
                    if (media != null)
                    {
                        await Functions.Instance.UploadImageToBlob("products", SelectedProduct.Image, SelectedProduct.SasQuery, media);
                    }
                }
                else
                {
                    await new MessageDialog("You have not internet connection!", "Insert Product").ShowAsync();
                    return false;
                }
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.Message.ToString(), "Notification!").ShowAsync();
                return false;
            }
            return true;
        }
示例#2
0
        private async void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            ToggleProgressRing();
            bool check = false;
            if (txtProductName.Text != "" && txtUnitPrice.Text != "" && txtUnit.Text != null 
                && txtAmount.Text != "" && txtSalePrice.Text != "" && cbStore.SelectedValue != null)
            {
                Product temp = new Product();
                temp.ProductName = txtProductName.Text;
                temp.UnitPrice = float.Parse(txtUnitPrice.Text);
                temp.Unit = txtUnit.Text;
                temp.NumberOf = Convert.ToInt32(txtAmount.Text);
                temp.SalePrice = float.Parse(txtSalePrice.Text);
                temp.StoreId = Convert.ToInt32(cbStore.SelectedValue);
                temp.ImportDate = DateTime.UtcNow;
                temp.About = txtAbout.Text;
                
                if (!ProductViewModel.isUpdate)
                {
                    check = await MediateClass.ProductVM.InsertProduct(temp, media);
                }
                else
                {
                    temp.ProductId = MediateClass.ProductVM.SelectedProduct.ProductId;
                    temp.Image = MediateClass.ProductVM.SelectedProduct.Image;
                    temp.SasQuery = MediateClass.ProductVM.SelectedProduct.SasQuery;                    

                    check = await MediateClass.ProductVM.UpdateProduct(temp, media);
                }
                if (check)
                {
                    await new MessageDialog("Successful!", "Product").ShowAsync();
                    Frame.GoBack();
                }
                else
                    await new MessageDialog("Not successful!", "Product").ShowAsync();
            }
            else
                await new MessageDialog("Please fill the infomation!", "Product").ShowAsync();
            ToggleProgressRing();
        }