public bool Salvar() { var ret = 0; var model = ConsultarPeloId(this.Id); using (var db = new ContextoDB()) { if (this.Cargo != null) { this.CargoId = this.Cargo.Id; this.Cargo = null; } if (model == null) { db.PessoaMap.Add(this); } else { db.PessoaMap.Attach(this); db.Entry(this).State = EntityState.Modified; } db.SaveChanges(); ret = this.Id; } return(!(ret == 0)); }
public CargoFuncionario ConsultarPeloId(int id) { CargoFuncionario ret = null; using (var db = new ContextoDB()) { ret = db.CargosMap.Find(id); } return(ret); }