private async void Window_Loaded(object sender, RoutedEventArgs e) { IsEnabled = false; var attempts = 0; var total = 5; while (attempts < total) { try { var equipments = await _equipmentService.GetAllAsync(); EquipmentDataGrid.ItemsSource = equipments; PublicEquipDataGrid = EquipmentDataGrid; var brands = await _brandService.GetAllAsync(); BrandDataGrid.ItemsSource = brands; PublicBrandDataGrid = BrandDataGrid; var tools = await _toolService.GetAllAsync(); ToolDataGrid.ItemsSource = tools; PublicToolDataGrid = ToolDataGrid; IsEnabled = true; break; } catch (Exception) { attempts++; Thread.Sleep(1000); } } if (attempts == total) { MessageBox.Show( "Сервер недоступен", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error ); Environment.Exit(1); } }
private async void OkButton_Click(object sender, RoutedEventArgs e) { var entity = _id == 0 ? new Tool() : await _toolService.GetAsync(_id); entity.Name = NameTextBox.Text; entity.Application = ApplicationTextBox.Text; try { if (_id == 0) { await _toolService.CreateAsync(entity); } else { await _toolService.UpdateAsync(entity); } MainWindow.PublicToolDataGrid.ItemsSource = await _toolService.GetAllAsync(); Close(); } catch (Exception exception) { MessageBox.Show("Server error"); } }
private async void Window_Loaded(object sender, RoutedEventArgs e) { var brands = await _brandService.GetAllAsync(); BrandComboBox.ItemsSource = brands; var tools = await _toolService.GetAllAsync(); ToolComboBox.ItemsSource = tools; }