private void btnRemover_Click(object sender, EventArgs e) { if (MessageBox.Show("Tem certeza que deseja remover o contato?", "Atenção", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { using (var _context = new DbContextFiap(App.ConnectionString)) { Contato _contato = (mainListContato.SelectedItem as Contato); _context.Contatos.Attach(_contato); _context.Contatos.DeleteOnSubmit(_contato); _context.SubmitChanges(); } App.ViewContato.Carregar(); } }
private void btnSalvar_Click(object sender, EventArgs e) { using (var _context = new DbContextFiap(App.ConnectionString)) { Contato _contato = new Contato() { Nome = txtNome.Text, Telefone = txtTelefone.Text, Email = txtEmail.Text }; try { _context.Contatos.InsertOnSubmit(_contato); _context.SubmitChanges(); if (NavigationService.CanGoBack) NavigationService.GoBack(); } catch (Exception error) { MessageBox.Show("Ocorreu um erro inesperado: " + error.Message); } } }