private void BtnSalvar_Click(object sender, EventArgs e)
        {
            using (var db = new PostgreContext())
            {
                var func = new Funcionario()
                {
                    Nome    = txtNome.Text,
                    Email   = txtEmail.Text,
                    CargoId = int.Parse(cboCargos.SelectedValue.ToString())
                };
                if (txtId.Text == String.Empty)
                {
                    db.Funcionarios.Add(func);
                }
                else
                {
                    func.Id = int.Parse(txtId.Text);
                    db.Entry(func).State = EntityState.Modified;
                }

                db.SaveChanges();
                MessageBox.Show("Funcionário salvo com sucesso.");
                Close();
            }
        }
Example #2
0
        private void BtnSalvar_Click(object sender, EventArgs e)
        {
            var cargo = new Cargo()
            {
                Descricao = txtDescricao.Text
            };

            using (var db = new PostgreContext())
            {
                if (txtId.Text == String.Empty)
                {
                    db.Cargos.Add(cargo);
                }
                else
                {
                    cargo.Id = int.Parse(txtId.Text);
                    db.Entry(cargo).State = EntityState.Modified;
                }
                db.SaveChanges();
            }
            MessageBox.Show("Cargo salvo com sucesso.");
            Close();
        }