public void Post(Contact c)
 {
     if (c != null)
     {
         Phonebook.Contacts.Add(c);
         JsonDataAccess da = new JsonDataAccess();
         da.SaveData();
     }
 }
Example #2
0
        private void CreateButton_Click(object sender, EventArgs e)
        {
            var id = Phonebook.Contacts.OrderByDescending(c => c.Id).First().Id;

            var contact = new Contact(++id, nameTextbox.Text, emailTextbox.Text, dobPicker.Value.Date, numberTextbox.Text);

            Phonebook.AddContactToList(contact);
            var reader = new JsonDataAccess();

            reader.SaveData();
            MessageBox.Show("Contact created.");
            Close();
        }
Example #3
0
        private void UpdateButton_Click(object sender, EventArgs e)
        {
            OriginalContact.Name   = UpdatedNameTextbox.Text;
            OriginalContact.Number = UpdatedNumberTextbox.Text;
            OriginalContact.Email  = UpdatedEmailTextbox.Text;
            OriginalContact.DOB    = UpdatedDobPicker.Value.Date;
            var dataAccess = new JsonDataAccess();

            dataAccess.SaveData();

            MessageBox.Show("Contact updated. Please refresh data.");

            Close();
        }
Example #4
0
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            var result = MessageBox.Show("You are about to delete a contact. This is a permanent action.\nAre you sure?", "Warning!", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                DataGridViewRow viewRow = phonebookGridView.SelectedRows[0];
                var             contact = Phonebook.Contacts.Where(c => c.Id == int.Parse(viewRow.Cells["Id"].Value.ToString())).FirstOrDefault();
                Phonebook.Contacts.Remove(contact);
                var dataAccess = new JsonDataAccess();
                dataAccess.SaveData();
                MessageBox.Show("Contact deleted.");
            }
            else
            {
                MessageBox.Show("Delete aborted.");
            }
            RefreshContactList();
        }