private async void OkButton_Click(object sender, RoutedEventArgs e) { if (!decimal.TryParse(PriceTextBox.Text, out var price)) { MessageBox.Show("Incorrect price"); return; } var entity = _id == 0 ? new Equipment() : await _equipmentService.GetAsync(_id); entity.Price = price; entity.Info = InfoTextBox.Text; entity.BrandId = (BrandComboBox.SelectedItem as Brand)?.Id ?? 0; entity.ToolId = (ToolComboBox.SelectedItem as Tool)?.Id ?? 0; try { if (_id == 0) { await _equipmentService.CreateAsync(entity); } else { await _equipmentService.UpdateAsync(entity); } MainWindow.PublicEquipDataGrid.ItemsSource = await _equipmentService.GetAllAsync(); Close(); } catch (Exception exception) { MessageBox.Show("Server error"); } }