public void setEmpresa(DtoEmpresa d) { Context db = new Context(); db.empresa.Add(d); db.SaveChanges(); }
private void btnSalvar_Click(object sender, EventArgs e) { try { model set = new model(); DtoEmpresa d = new DtoEmpresa(); d.nome = textBoxNome.Text; d.endereco = textBoxEndereco.Text; d.latitude = Convert.ToDouble(textBoxLatitude.Text, CultureInfo.InvariantCulture); d.longitude = Convert.ToDouble(textBoxLongitude.Text, CultureInfo.InvariantCulture); if (textBoxID.Text == string.Empty) { set.setEmpresa(d); } else { d.id = int.Parse(textBoxID.Text); set.AlteraEmpresa(d); } MessageBox.Show("Registro salvo com sucesso"); this.Close(); } catch (Exception ex) { throw ex; } }
public void DeleteEmpresa(int id) { Context db = new Context(); DtoEmpresa e = db.empresa.FirstOrDefault(p => p.id == id); db.empresa.Remove(e); db.SaveChanges(); }
public void AlteraEmpresa(DtoEmpresa d) { Context db = new Context(); DtoEmpresa e = db.empresa.FirstOrDefault(p => p.id == d.id); e.nome = d.nome; e.endereco = d.endereco; e.latitude = d.latitude; e.longitude = d.longitude; db.SaveChanges(); }
public FrmEmpresa() { InitializeComponent(); model get = new model(); DtoEmpresa e = get.getEndEmpresa(); if (e != null) { textBoxID.Text = e.id.ToString(); textBoxNome.Text = e.nome.ToString(); textBoxLatitude.Text = e.latitude.ToString(); textBoxLongitude.Text = e.longitude.ToString(); textBoxEndereco.Text = e.endereco.ToString(); } }