Exemple #1
0
 private void DeleteSelectedUserButton_Click(object sender, RoutedEventArgs e)
 {
     using (var ctx = new FriendsModelContainer())
     {
         var userToDelete = ctx.Friends.Find(SelectedFriend.FriendId);
         if (userToDelete != null)
         {
             ctx.Friends.Remove(userToDelete);
             Friends.Remove(SelectedFriend);
             UsersListBox.SelectedIndex = 0;
             ctx.SaveChanges();
         }
     }
 }
Exemple #2
0
        private void AddUserButton_Click(object sender, RoutedEventArgs e)
        {
            AddUserWindow addUserWindow = new AddUserWindow();

            if (addUserWindow.ShowDialog() == true)
            {
                Friends.Add(addUserWindow.NewFriend);
                using (var ctx = new FriendsModelContainer())
                {
                    ctx.Friends.Add(addUserWindow.NewFriend);
                    ctx.SaveChanges();
                }
            }
            else
            {
            }
        }