private void button3_Click(object sender, EventArgs e) { //Login List <Contact> list; GoogleSync gs = new GoogleSync(); gs.Login(); using (var ctx = new ContactContext()) { list = ctx.Contacts.ToList(); foreach (var item in list) { if (gs.Contacts == null) { return; } bool found = false; for (int i = 0; i < gs.Contacts.Count; i++) { if (item.IsMatch(gs.Contacts[i])) { found = true; break; } } if (!found) { gs.CreateContact(item); } } } gs.GetContactsFromGoogle(); gs.WriteContactsToDatabase(); UpdateTable(); }
private void button2_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count == 0) { MessageBox.Show("Please select a row to delete."); return; } using (var ctx = new ContactContext()) { var contact = new Contact() { ContactId = int.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString()), FirstName = dataGridView1.SelectedRows[0].Cells[1].Value.ToString(), LastName = dataGridView1.SelectedRows[0].Cells[2].Value.ToString(), CompanyName = dataGridView1.SelectedRows[0].Cells[3].Value.ToString(), JobTitle = dataGridView1.SelectedRows[0].Cells[4].Value.ToString(), PhoneNumber = dataGridView1.SelectedRows[0].Cells[5].Value.ToString() }; ctx.Contacts.Attach(contact); ctx.Contacts.Remove(contact); GoogleSync gs = new GoogleSync(); gs.Login(); foreach (Google.Contacts.Contact c in gs.Contacts) { if (contact.IsMatch(c)) { gs.DeleteContact(c); break; } } ctx.SaveChanges(); UpdateTable(); } }