Пример #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            using (var ctx = new FriendsModelContainer())
            {
                Friends = new ObservableCollection <Friend>(ctx.Friends.ToList());
            }

            UsersListBox.ItemsSource = Friends;
        }
Пример #2
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            using (var ctx = new FriendsModelContainer())
            {
                NewFriend.FirstName  = FirstNameTextBox.Text;
                NewFriend.MiddleName = MiddleNameTextBox.Text;
                NewFriend.LastName   = LastNameTextBox.Text;

                DialogResult = true;
            }

            Close();
        }
Пример #3
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();
         }
     }
 }
Пример #4
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
            {
            }
        }