private void SaveChangesButton_Click(object sender, RoutedEventArgs e) { //get data from the form string firstName = FirstNameTextBox.Text; string lastName = LastNameTextBox.Text; string phone = PhoneTextBox.Text; string city = ((ComboBoxItem)CityComboBox.SelectedItem).Content.ToString(); List <String> errorsList = Guardian.FindGuardianValidationErrors(firstName, lastName, phone); if (errorsList.Count() == 0)//if there are no errors { Guardian updatedGuardian = new Guardian(guardian.GuardianId, firstName, lastName, phone, city); UpdateGuardian(updatedGuardian); } else { //show dialog with information which data were incorrect var errorString = String.Join("\n", errorsList.ToArray()); MessageBoxResult result = MessageBox.Show(errorString, ErrorText, MessageBoxButton.OK, MessageBoxImage.Error); } }
private void AddGuardianButton_Click(object sender, RoutedEventArgs e) {//todo split to functions somehow? string firstName = FirstNameTextBox.Text; string lastName = LastNameTextBox.Text; string phone = PhoneTextBox.Text; string city = ((ComboBoxItem)CityComboBox.SelectedItem).Content.ToString(); List <String> errorsList = Guardian.FindGuardianValidationErrors(firstName, lastName, phone); if (errorsList.Count() == 0)//if there are no errors { Guardian guardian = new Guardian(firstName, lastName, phone, city); AddGuardian(guardian); } else { //show dialog with information which data were incorrect var errorString = String.Join("\n", errorsList.ToArray()); MessageBoxResult result = System.Windows.MessageBox.Show(errorString, ErrorText, MessageBoxButton.OK, MessageBoxImage.Error); } }