private void btnFind_Click(object sender, EventArgs e) { try { int ID = int.Parse(txtProductID.Text); HttpResponseMessage resp = client.GetAsync(baseUri + ID).Result; resp.EnsureSuccessStatusCode(); RemoteService.Models.Products products = resp.Content.ReadAsAsync <RemoteService.Models.Products>().Result; if (products == null) { MessageBox.Show("Product not found."); } else { txtProductName.Text = products.ProductName; txtProductPrice.Text = products.UnitPrice.ToString(); txtProductQuantity.Text = products.Quantity.ToString(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnAdd_Click(object sender, EventArgs e) { try { int ID = int.Parse(txtProductID.Text); string Name = txtProductName.Text; float Price = float.Parse(txtProductPrice.Text); int Quantity = int.Parse(txtProductQuantity.Text); RemoteService.Models.Products products = new RemoteService.Models.Products { ProductID = ID, ProductName = Name, UnitPrice = Price, Quantity = Quantity }; HttpResponseMessage resp = client.PostAsJsonAsync(baseUri, products).Result; resp.EnsureSuccessStatusCode(); MessageBox.Show("Product is saved"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }