示例#1
0
        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");
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            ContactsRepo repo = new ContactsRepo();

            Console.WriteLine("Visa kontaktlista? (J/N)");
            var response = Console.ReadLine();

            switch (response.ToUpper())
            {
            case "J":
                var allContacts = repo.GetAllContacts();
                foreach (var contact in allContacts)
                {
                    Console.WriteLine(contact.ToString());
                }
                break;

            default:
                break;
            }
        }
示例#3
0
        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;
            }
        }
示例#4
0
        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);
            }
        }
示例#5
0
        public void loadContactsFromDb()
        {
            ContactsRepo contRepo = ContactsRepo.Instance();

            resultsList = contRepo.getAllCurrentContacts();
        }