private void Button_Click(object sender, RoutedEventArgs e) { var x = (SearchResult)listView.SelectedItem; if (x != null) { ContactsRepo contactRepo = ContactsRepo.Instance(); int subject_id = Int32.Parse(UserRepo.GetColumnValueByUsername(x.Username, "user_id")); int owner_id = Int32.Parse(UserRepo.GetColumnValueByUsername(Globals.currentUserLogin, "user_id")); DateTime created_date = DateTime.Now; int is_favourite = 0; if (contactRepo.contactExists(owner_id, subject_id)) { MessageBox.Show("You already have this user in your contacts"); } else if (owner_id == subject_id) { MessageBox.Show("You can't add yourself to contacts"); } else { contactRepo.createContact(owner_id, subject_id, is_favourite); MessageBox.Show("Contact added sucessfully"); ((WindowMain)this.Owner).refreshListBox(); } } else { MessageBox.Show("Select user to add"); } }