private void SaveExecute() { try { if (Product.Price <= 0) { MessageBox.Show("Price must be greater than 0"); return; } if (Product.Amount <= 0) { MessageBox.Show("Amount must be greater than 0"); return; } if (!Product.ProductName.Equals(oldName) && dataService.GetProductByName(Product.ProductName) != null) { MessageBox.Show("Product with this name already exists."); return; } if (!Product.Code.Equals(oldCode) && dataService.GetProductByCode(Product.Code) != null) { MessageBox.Show("Product with this code already exists."); return; } if (!ValidationClass.IsProductCodeValid(Product.Code)) { MessageBox.Show("Product code is not valid. It has to be 7 characters long\n" + "and it can contain only digits"); return; } dataService.EditProduct(Product); isUpdateProduct = true; editProduct.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }