Beispiel #1
0
 public static async Task<HttpResponseMessage> Delete(Product product)
 {
     using (var c = APIService.GetClient())
     {
         return await c.DeleteAsync($"products/{product.Id}");
     }
 }
Beispiel #2
0
 private async void buttonAdd_Click(object sender, RoutedEventArgs e)
 {
     Manufacturer manufacturer = (Manufacturer)comboBoxManufacturer.SelectedItem;
     int manufacturerId = manufacturer.Id;
     string description = textBoxDescription.Text.Trim();
     decimal price = -1;
     decimal.TryParse(textBoxPrice.Text.Trim(), NumberStyles.Any, new CultureInfo("pt-BR"), out price);
     int stock = -1;
     int.TryParse(textBoxStock.Text.Trim(), out stock);
     if (manufacturerId > 0 && !String.IsNullOrEmpty(description) && stock >= 0 && price >= 0)
     {
         Product product = new Product()
         {
             ManufacturerId = manufacturerId,
             Description = description,
             Price = price,
             Stock = stock
         };
         HttpResponseMessage responde = await Product.Add(product);
         if (responde.IsSuccessStatusCode)
         {
             InitDataGrid();
             ClearFields();
             MessageBox.Show($"Product {product.Description} of {manufacturer.Description} was added");
         }
         else
         {
             MessageBox.Show($"Product {product.Description} of {manufacturer.Description} wasn't added");
         }
     }
     else
     {
         MessageBox.Show("All fields are required...");
     }
 }
Beispiel #3
0
 public static async Task<HttpResponseMessage> Edit(Product product)
 {
     using (var c = APIService.GetClient())
     {
         string json = JsonConvert.SerializeObject(product);
         StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
         return await c.PutAsync($"products/{product.Id}", content);
     }
 }