private void BtnAddProduct_Click(object sender, RoutedEventArgs e) { // Navigate from this view to another view. MainHomeWindow mainWindow = (MainHomeWindow)Window.GetWindow(this); mainWindow.mainContent.Content = new AddProductViewModel(); }
private void ButtonEdit_Click(object sender, RoutedEventArgs e) { // Get Product data from the selected row in the data grid. Product product = (Product)((Button)e.Source).DataContext; int productId = product.ProductId; // Set productId into App.Current.Properties. This treats productId like a global variable. Application.Current.Properties["productId"] = productId; // Navigate from this view to another view. MainHomeWindow mainWindow = (MainHomeWindow)Window.GetWindow(this); mainWindow.mainContent.Content = new EditProductViewModel(); }
private async void BtnSave_Click(object sender, RoutedEventArgs e) { MessageBoxResult result; result = MessageBox.Show("You want to edit products? ", "Question", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { // Get input data from current view. string name = txtName.Text; string detail = txtDetail.Text; float price = float.Parse(txtPrice.Text); string status = txtStatus.Text; string unit = txtUnit.Text; // Create new Product model to push it to the AddProduct function. Product product = new Product() { Name = name, Detail = detail, Price = price, Status = status, Unit = unit }; // Function call the API to add Product and get response data. var response = await productService.UpdateProductView(product); var responseData = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { // Show the response message from the server. MessageBox.Show(responseData, "Response Message"); // Clear all input fields. Reset(); // Change response message text to Green. textBlockResponseMessage.Foreground = Brushes.Green; } else { // Change response message text to Red. textBlockResponseMessage.Foreground = Brushes.Red; } // Show the response message from the server. textBlockResponseMessage.Text = responseData; MainHomeWindow mainHome = new MainHomeWindow(); mainHome.Content = new ProductView(); } }