private void button1_Click(object sender, EventArgs e) { if (textBox1.Text.Length == 0 || textBox2.Text.Length == 0 || textBox3.Text.Length == 0 || textBox4.Text.Length == 0 || textBox5.Text.Length == 0) { MessageBox.Show("Please enter data."); return; } using (var ctx = new ContactContext()) { var contact = new Contact(textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text); try { ctx.Contacts.Add(contact); GoogleSync gs = new GoogleSync(); gs.Login(); gs.CreateContact(contact); gs.WriteContactsToDatabase(); ctx.SaveChanges(); }catch (Exception ex) { MessageBox.Show(ex.Message); } } this.Close(); }
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(); }