private void RunAsync() { client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:50236"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { Products = HttpServices.GetAllProductsAsync(client); } catch (Exception e) { Trace.WriteLine(e.Message); } }
private void Add_Click(object sender, RoutedEventArgs e) { ObservableCollection <NewProduct> lproducts = (ObservableCollection <NewProduct>) this.FindResource("products"); foreach (var item in lproducts) { Product tmp = new Product(); tmp.Name = item.Name; if (item.PurchPriceDol != null && item.PurchPriceDol != 0) { tmp.PurchPriceDol = item.PurchPriceDol; } else { tmp.PurchPriceSol = item.PurchPriceSol; } tmp.RetailPrice = item.RetailPrice; tmp.WholesalePrice = item.WholesalePrice; tmp.Stock = item.Quantity; HttpServices.CreateProductAsync(client, tmp); } MessageBox.Show("Productos Agregados correctamente"); this.Close(); /* * List<NewProduct> newProducts = AddProductsList.Items.OfType<NewProduct>().ToList(); * Trace.WriteLine(newProducts[0].Quantity); * Trace.WriteLine(newProducts[0].Name); * Trace.WriteLine(newProducts[0].PurchPriceDol); * Trace.WriteLine(newProducts[0].PurchPriceSol); * Trace.WriteLine(newProducts[0].WholesalePrice); * Trace.WriteLine(newProducts[0].RetailPrice); */ /* * for (int i = 0; i < AddProductsList.Items.Count; i++) * { * var row = (DataGridRow)AddProductsList.ItemContainerGenerator.ContainerFromIndex(i); * Trace.WriteLine(row); * }*/ }
public void RunAsync() { HttpClient client = new HttpClient { BaseAddress = new Uri("http://localhost:50236") }; client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { //var list = HttpServices.GetAllProductsAsync(client); //ProductList.ItemsSource = list; Source = HttpServices.GetAllProductsAsync(client); } catch (Exception e) { Trace.WriteLine(e.Message); } }
private void Update_Click(object sender, RoutedEventArgs e) { exrate = Convert.ToDouble(ExchangeRate.Text); foreach (var item in Products) { if (item.PurchPriceDol != null) { item.PurchPriceSol = item.PurchPriceDol * exrate; try { HttpServices.UpdateProductAsync(client, item); } catch (Exception ex) { Trace.WriteLine(ex.Message); } } } ProductsList.ItemsSource = null; ProductsList.ItemsSource = Products; File.WriteAllText("exrate.txt", exrate + ""); MessageBox.Show("Lista Actualizada"); }