Пример #1
0
 public void DeleteFriend(Friend deleteFriend)
 {
     using (AddressBookContext dataContext = new AddressBookContext())
     {
         Friend friendToDelete = dataContext.Friends.Single(t => t.ID == deleteFriend.FirstName);
         dataContext.Friends.Remove(friendToDelete);
         dataContext.SaveChanges();
     }
 }
Пример #2
0
        public void UpdateFriend(Friend updatefriend)
        {
            using (AddressBookContext dataContext = new AddressBookContext())
            {
                Friend friendToUpdate = dataContext.Friends.Single(t => t.FirstName == updatefriend.FirstName);
                updatefriend.FirstName = updatefriend.FirstName;
                updatefriend.LastName = updatefriend.LastName;
                updatefriend.Street = updatefriend.Street;
                updatefriend.State = updatefriend.State;
                updatefriend.Zip = updatefriend.Zip;

                dataContext.SaveChanges();
            }
        }
Пример #3
0
 public void AddFriend(Friend newFriend)
 {
     using (AddressBookContext dataContext = new AddressBookContext())
     {
         Friend friend = new Friend
         {
             FirstName = newFriend.FirstName,
             LastName = newFriend.LastName,
             Street = newFriend.Street,
             State = newFriend.State,
             Zip = newFriend.Zip,
         };
         dataContext.Friends.Add(friend);
         dataContext.SaveChanges();
     }
 }
Пример #4
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtFirstName.Text.Trim().Length == 0  || txtLastName.Text.Trim().Length == 0 || txtStreet.Text.Trim().Length == 0 || txtZip.Text.Trim().Length == 0)
            {
                MessageBox.Show("Please fill in all information", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

                else
                {
                     Friend newfriend = new Friend()
                     {
                          FirstName = txtFirstName.Text,
                          LastName = txtLastName.Text,
                          Street = txtStreet.Text,
                          State = cbStateAbbrevs.Text,
                          Zip =Convert.ToInt32(txtZip.Text),
                      };

                     Business.FriendCRUD friendCRUD = new Business.FriendCRUD();
                     friendCRUD.AddFriend(newfriend);

                     MessageBox.Show("New friend was successfully added", "Successful Add", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                     // Add new Friend to list box
                     Fill_lstBoxFriends();

                     // Clear text boxes to be ready for next entry
                     txtFirstName.Clear();
                     txtLastName.Clear();
                     txtStreet.Clear();
                     txtZip.Clear();
                  }
        }