// GET patrimonios/{id} - Obter um patrimônio por ID public Patrimonio GetPatrimonio(int?id) { Patrimonio p = new Patrimonio(); using (SqlConnection con = new SqlConnection(connectionString)) { string sqlQuery = "SELECT * FROM Patrimonio WHERE PatrimonioID= " + id; SqlCommand cmd = new SqlCommand(sqlQuery, con); con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { p.Id = Convert.ToInt32(rdr["PatrimonioId"]); p.Nome = rdr["Nome"].ToString(); p.Descricao = rdr["Descricao"].ToString(); p.NumTombo = Convert.ToInt32(rdr["NumTombo"]); p.MarcaId = Convert.ToInt32(rdr["MarcaId"]); } } return(p); }