//public void Deletar(Paciente p) { // try { // using (Conexao Con = new Conexao()) { // Con.Entry(p).State = EntityState.Deleted; // Con.SaveChanges(); // } // } // catch (Exception e) { // throw new Exception(e.ToString()); // } //} public void Delete(Paciente p) { try { using (Conexao Con = new Conexao()) { p.User = null; p.Sangue = null; User u = new User(); List <Consulta> lista = Con.Consultas.AsNoTracking().Where(c => c.IdPaciente == p.Id).ToList(); lista.ForEach(l => l.Paciente.User = null); lista.ForEach(l => l.Medico = null); lista.ForEach(l => l.Paciente = p); foreach (var item in lista) { Con.Entry(item).State = EntityState.Deleted; } Con.Entry(p).State = EntityState.Deleted; Con.SaveChanges(); UserRoles urs = UserRolesDal.FindByUserId(p.IdUser); UserRolesDal.Deletar(urs); UserDal.Deletar(UserDal.FindByKey(p.IdUser)); Con.SaveChanges(); } } catch (Exception e) { throw new Exception("Erro ao Deletar Consulta: " + e.ToString()); } }
//public Medico GetOne(int m) { // Medico md = new Medico(); // try { // using (Conexao Con = new Conexao()) { // try { // md = Con.Medicos.FirstOrDefault(x => x.Id == m); // md.Especialidade = Con.Especialidades.FirstOrDefault(z => z.Id == md.IdEspecialidade); // } // catch (Exception e) { // throw new Exception(e.ToString()); // } // return md; // } // } // catch (Exception e) { // throw new Exception(e.ToString()); // } //} public void AlterarEspecialidade(int m, int e) { Medico md = new Medico(); try { using (Conexao Con = new Conexao()) { var result = Con.Medicos.SingleOrDefault(x => x.Id == m); if (result != null) { try { result.IdEspecialidade = e; result.Especialidade = Con.Especialidades.FirstOrDefault(f => f.Id == e); Con.Entry(result).State = EntityState.Modified; Con.SaveChanges(); } catch (Exception z) { throw new Exception(z.ToString()); } } } } catch (Exception) { throw; } }
public void Alterar(Especialidade es) { try { using (Conexao Con = new Conexao()) { Con.Entry(es).State = EntityState.Modified; Con.SaveChanges(); } }catch (Exception e) { throw new Exception(e.ToString()); } }
public void Alterar(Paciente p) { try { using (Conexao Con = new Conexao()) { Con.Entry(p).State = EntityState.Modified; Con.SaveChanges(); } } catch (Exception e) { throw new Exception(e.ToString()); } }
public void Update(ContaPagar c) { try { using (Conexao Con = new Conexao()) { Con.Entry(c).State = EntityState.Modified; Con.SaveChanges(); } } catch { throw; } }
public void Update(Receita r) { try { using (Conexao Con = new Conexao()) { Con.Entry(r).State = EntityState.Modified; Con.SaveChanges(); } } catch { throw; } }
public void Alterar(Aluno a) { Con.Aluno.Attach(a); Con.Entry(a).State = System.Data.Entity.EntityState.Modified; Con.SaveChanges(); }
public void Alterar(Responsavel r) { Con.Responsavel.Attach(r); Con.Entry(r).State = System.Data.Entity.EntityState.Modified; Con.SaveChanges(); }
public void Alterar(Cidade c) { Con.Cidade.Attach(c); Con.Entry(c).State = System.Data.Entity.EntityState.Modified; Con.SaveChanges(); }
public void Alterar(Endereco e) { Con.Endereco.Attach(e); Con.Entry(e).State = System.Data.Entity.EntityState.Modified; Con.SaveChanges(); }