private void btnEditContact_Click(object sender, RoutedEventArgs e) { if (lvContacts.SelectedItem != null) { PersonBO cc = lvPersons.SelectedItem as PersonBO; ContactBO contact = new ContactBO((lvContacts.SelectedItem as ContactBO).Id, contactValueBox.Text, (lvPersons.SelectedItem as PersonBO).Id, ((cBoxContactTypes.SelectedItem) as ContactTypeBO).Id); if (contact.Id == 1 || cBoxContactTypes.SelectedItem.Equals("Email")) { if (!IsValid(contactValueBox.Text)) { MessageBoxResult result = MessageBox.Show("The email is invalid, aborting", "Warning", MessageBoxButton.OK); return; } } contact.AddOrUpdate(); this._vm._contacts = cc.Contacts; lvContacts.ItemsSource = _vm.Contacts; lvContacts.UpdateLayout(); } else { MessageBoxResult result = MessageBox.Show("Select a Contact to edit first", "Warning", MessageBoxButton.OK); } e.Handled = true; }
private void btnAddContact_Click(object sender, RoutedEventArgs e) { if (_vm.ContactTypes.Count > 0) { if (!contactValueBox.Text.Equals("")) { PersonBO a = lvPersons.SelectedItem as PersonBO; ContactTypeBO contactType = cBoxContactTypes.SelectedItem as ContactTypeBO; if (a != null) { ContactBO cbo = new ContactBO(contactValueBox.Text, (lvPersons.SelectedItem as PersonBO).Id, (cBoxContactTypes.SelectedItem as ContactTypeBO).Id); if (contactType.Name.Equals("Email")) { if (!IsValid(contactValueBox.Text)) { MessageBoxResult result = MessageBox.Show("The email is invalid, aborting", "Warning", MessageBoxButton.OK); return; } } cbo.AddOrUpdate(); this._vm._contacts = a.Contacts; lvContacts.ItemsSource = _vm.Contacts; lvContacts.UpdateLayout(); } else { MessageBox.Show("Select a Person first, to whom you want to add the contact", "A big fat warning", MessageBoxButton.OK); } } else { MessageBox.Show("Contact value can not be empty", "Warning", MessageBoxButton.OK); } } else { MessageBox.Show("Add atleast one contact type first", "Warning", MessageBoxButton.OK); } e.Handled = true; }