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"); } }
private void FavouriteClick(object sender, RoutedEventArgs e) { var selectedItem = listBox.SelectedItem; string text = (string)listBox.SelectedItem; if (text == null) { MessageBox.Show("No user selected"); } else { ContactsRepo contRepo = ContactsRepo.Instance(); Contact selectedContact = getContactByUsername(text); contRepo.toggleFavourite(selectedContact.SubjectId, Globals.currentUserId); MessageBox.Show("Change sucessfully saved"); refreshListBox(); favourite.Content = "Mark as favourite"; TextName.Text = text; listBox.SelectedItem = selectedItem; } }
private void Remove_Click(object sender, RoutedEventArgs e) { string text = (string)listBox.SelectedItem; if (text == null) { MessageBox.Show("No user selected"); } else { TextName.Text = ""; imageProfile.Source = null; favourite.Content = "Mark as favourite"; ContactsRepo contRepo = ContactsRepo.Instance(); Contact selectedContact = getContactByUsername(text); contRepo.removeContact(selectedContact.SubjectId, Globals.currentUserId); MessageBox.Show("Change sucessfully saved"); refreshListBox(); ButtonSet(false, false, false); } }
public void loadContactsFromDb() { ContactsRepo contRepo = ContactsRepo.Instance(); resultsList = contRepo.getAllCurrentContacts(); }