public void InserirAnalistaDB(Analistas analista) { try { IDbCommand insertCmd = conexao.CreateCommand(); insertCmd.CommandText = "insert into Analista (nome, telefone, idade) values (@nome, @telefone, @idade)"; IDbDataParameter paramNome = new SqlParameter("nome", analista.nome); insertCmd.Parameters.Add(paramNome); IDbDataParameter paramTelefone = new SqlParameter("telefone", analista.telefone); insertCmd.Parameters.Add(paramTelefone); IDbDataParameter paramIdade = new SqlParameter("idade", analista.idade); insertCmd.Parameters.Add(paramIdade); insertCmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { conexao.Close(); } }
// POST: api/Analista public List <Analistas> Post(Analistas analista) { Analistas _analista = new Analistas(); _analista.Inserir(analista); return(_analista.ListarAnalista()); }
public void AtualizarAlunoDB(Analistas analista) { try { IDbCommand updateCmd = conexao.CreateCommand(); updateCmd.CommandText = "update Analistas set nome = @nome,cpf = @cpf, telefone = @telefone, email = @email where id = @id"; IDbDataParameter paramNome = new SqlParameter("nome", analista.nome); IDbDataParameter paramTelefone = new SqlParameter("telefone", analista.telefone); IDbDataParameter paramIdade = new SqlParameter("idade", analista.idade); updateCmd.Parameters.Add(paramNome); updateCmd.Parameters.Add(paramTelefone); updateCmd.Parameters.Add(paramIdade); IDbDataParameter paramID = new SqlParameter("id", analista.id); updateCmd.Parameters.Add(paramID); updateCmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { conexao.Close(); } }
// PUT: api/Analista/5 public List <Analistas> Put(int id, Analistas analista) { Analistas _analista = new Analistas(); _analista.id = id; _analista.Atualizar(analista); return(_analista.ListarAnalista()); }
public IHttpActionResult Get() { try { Analistas analista = new Analistas(); return(Ok(analista.ListarAnalista())); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult Recuperar(string data, string nome) { try { Analistas analistas = new Analistas(); IEnumerable <Analistas> analista = analistas.ListarAnalista().Where(x => x.data == data || x.nome == nome); if (!analista.Any()) { return(NotFound()); } return(Ok(analista)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public List <Analistas> ListarAnalistaDB(int?id = null) { var listaAnalista = new List <Analistas>(); try { IDbCommand selectCmd = conexao.CreateCommand(); if (id == null) { selectCmd.CommandText = "select * from Analista"; } else { selectCmd.CommandText = $"select * from Analista where id = {id}"; } IDataReader resultado = selectCmd.ExecuteReader(); while (resultado.Read()) { var ana = new Analistas(); ana.id = Convert.ToInt32(resultado["Id"]); ana.nome = Convert.ToString(resultado["nome"]); ana.cpf = Convert.ToInt32(resultado["cpf"]); ana.telefone = Convert.ToString(resultado["telefone"]); ana.email = Convert.ToString(resultado["email"]); ana.idade = Convert.ToInt32(resultado["idade"]); listaAnalista.Add(ana); } return(listaAnalista); } catch (Exception ex) { throw new Exception(ex.Message); } finally { conexao.Close(); } }
internal void AtualizarAnalistaDB(Analistas analista) { throw new NotImplementedException(); }
// DELETE: api/Analista/5 public void Delete(int id) { Analistas _Analista = new Analistas(); _Analista.Deletar(id); }
public Analistas Get(int id) { Analistas aluno = new Analistas(); return(aluno.ListarAnalista().Where(x => x.id == id).FirstOrDefault()); }