public static bool Alterar(Comida_Ingrediente comida) { try { using (OracleCommand c = ConexaoOracle.ObterConexao().CreateCommand()) { c.CommandType = System.Data.CommandType.Text; c.CommandText = "UPDATE Comida_Ingrediente SET quantidade = :quantidade WHERE ingredienteid = :ingrediente and produtoid = :produto"; c.Parameters.Add("quantidade", OracleType.Int32).Value = comida.getQuantidade(); c.Parameters.Add("ingrediente", OracleType.Int32).Value = comida.getIngredienteId(); c.Parameters.Add("produto", OracleType.Int32).Value = comida.getProdutoId(); c.ExecuteNonQuery(); return true; } } catch (OracleException e) { throw e; } }
public static Comida_Ingrediente BuscarIngredienteNome(String nome) { Comida_Ingrediente comida = null; try { using (OracleCommand c = ConexaoOracle.ObterConexao().CreateCommand()) { c.CommandType = System.Data.CommandType.Text; c.CommandText = "SELECT comida_ingredienteid, ingredienteid, produtoid, quantidade FROM comida_ingrediente join ingredientes USING(ingredienteid) WHERE nome = :nome"; c.Parameters.Add("nome", OracleType.VarChar).Value = nome; using (OracleDataReader leitor = c.ExecuteReader()) { while (leitor.Read()) { int bd_comida_ingredienteid = leitor.GetInt32(0); int bd_ingredienteid = leitor.GetInt32(1); int bd_produtoid = leitor.GetInt32(2); int bd_quantidade = leitor.GetInt32(3); comida = new Comida_Ingrediente(bd_comida_ingredienteid, bd_ingredienteid, bd_produtoid, bd_quantidade); } } } return comida; } catch (NullReferenceException e) { throw e; } }
public static bool Inserir(Comida_Ingrediente comida) { using (OracleCommand c = ConexaoOracle.ObterConexao().CreateCommand()) { c.CommandType = System.Data.CommandType.Text; c.CommandText = "INSERT INTO Comida_Ingrediente values(comida_ingrediente_seq.nextval, :ingredienteid, :produtoid, :quantidade)"; c.Parameters.Add("ingredienteid", OracleType.Int32).Value = comida.getIngredienteId(); c.Parameters.Add("produtoid", OracleType.Int32).Value = comida.getProdutoId(); c.Parameters.Add("quantidade", OracleType.Int32).Value = comida.getQuantidade(); c.ExecuteScalar(); return true; } }
public static bool Gravar(Comida_Ingrediente comida) { return Inserir(comida); }
public static bool ValidaCaracter(Comida_Ingrediente comida) { if (comida.getQuantidade() < 1) throw new CaracterInvalidoException("A quantidade de ingrediente deve ser maior que zero!"); return true; }
public static bool Salvar(Comida_Ingrediente comida) { if (ValidaCaracter(comida)) return Comida_IngredienteDAO.Gravar(comida); return false; }