private async void OK_Click(object sender, RoutedEventArgs e) { try { Category c = DataContext as Category; if (c != null) { if (string.IsNullOrEmpty(c.CategoryName)) { MessageBox.Show("The category name cannot be empty!", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (_CategoryId > 0) { ProductHttpClientWrapper wrapper = new ProductHttpClientWrapper(); await wrapper.Category.UpdateCategory(c); } else { ProductHttpClientWrapper wrapper = new ProductHttpClientWrapper(); await wrapper.Category.CreateCategory(c); } Close(); if (CallbackAction != null) { CallbackAction(); } } } catch (Exception ex) { MessageBox.Show(string.Format("Failed to save the category!\r\nError Message:\r\n{0}", ex), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
public async void SetProductId(int productId) { _ProductId = productId; if (_ProductId > 0) { ProductHttpClientWrapper wrapper = new ProductHttpClientWrapper(); var result = await wrapper.Product.GetProductById(_ProductId); DataContext = result; } }
public async void SetCategoryId(int categoryId) { _CategoryId = categoryId; if (_CategoryId > 0) { ProductHttpClientWrapper wrapper = new ProductHttpClientWrapper(); var result = await wrapper.Category.GetCategoryById(_CategoryId); DataContext = result; } }
private async void Window_Loaded(object sender, RoutedEventArgs e) { ProductHttpClientWrapper wrapper = new ProductHttpClientWrapper(); var result = await wrapper.Category.GetAllCategories(); List <Category> lstCategory = new List <Category>(result); lstCategory.Insert(0, new Category() { CategoryId = 0, CategoryName = "--- Please select one category ---" }); cbCategory.ItemsSource = lstCategory; }
private async void OK_Click(object sender, RoutedEventArgs e) { try { Product c = DataContext as Product; if (c != null) { if (string.IsNullOrEmpty(c.ProductName)) { MessageBox.Show("The product name cannot be empty!", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning); return; } else if (c.Quantity <= 0) { MessageBox.Show("The product quantity cannot be negative!", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning); return; } else if (c.CategoryId <= 0) { MessageBox.Show("Please select one category!", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (_ProductId > 0) { ProductHttpClientWrapper wrapper = new ProductHttpClientWrapper(); await wrapper.Product.UpdateProduct(c); } else { ProductHttpClientWrapper wrapper = new ProductHttpClientWrapper(); await wrapper.Product.CreateProduct(c); } Close(); if (CallbackAction != null) { CallbackAction(); } } } catch (Exception ex) { MessageBox.Show(string.Format("Failed to save the product!\r\nError Message:\r\n{0}", ex), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }