Пример #1
0
        private void btnSalvar_Click(object sender, RoutedEventArgs e)
        {
            //gravar no banco de dados

            if (this.operacao == "inserir")
            {
                contato c = new contato();
                c.nome     = txtNome.Text;
                c.email    = txtEmail.Text;
                c.telefone = txtTel.Text;
                using (agendaEntities ctx = new agendaEntities())
                {
                    ctx.contatos.Add(c);
                    ctx.SaveChanges();
                }
            }
            if (this.operacao == "alterar")
            {
                using (agendaEntities ct = new agendaEntities())
                {
                    contato c = ct.contatos.Find(Convert.ToInt32(txtID.Text));
                    if (c != null)
                    {
                        c.nome     = txtNome.Text;
                        c.email    = txtEmail.Text;
                        c.telefone = txtTel.Text;
                        ct.SaveChanges();
                    }
                }
            }
            this.ListarContatos();
            this.AlterarBotoes(1);
            this.LimpaCampos();
        }
Пример #2
0
 private void btnExcluir_Click(object sender, RoutedEventArgs e)
 {
     using (agendaEntities ctx = new agendaEntities())
     {
         contato c = ctx.contatos.Find(Convert.ToInt32(txtID.Text));
         if (c != null)
         {
             ctx.contatos.Remove(c);
             ctx.SaveChanges();
         }
         this.ListarContatos();
         this.AlterarBotoes(1);
         this.LimpaCampos();
     }
 }