public static IngredientAdjustment Add(int employeeId, int ingredientId, double?originalValue, double?newValue, MeasurementUnit measurementUnit, int?recipeIngredientId = null, DateTime?when = null) { IngredientAdjustment result = null; SqlConnection cn = GetConnection(); if (when == null) { when = DateTime.Now; } string cmd = "AddIngredientAdjustment"; using (SqlCommand sqlCmd = new SqlCommand(cmd, cn)) { sqlCmd.CommandType = CommandType.StoredProcedure; BuildSqlParameter(sqlCmd, "@IngredientAdjustmentEmployeeId", SqlDbType.Int, employeeId); BuildSqlParameter(sqlCmd, "@IngredientAdjustmentIngredientId", SqlDbType.Int, ingredientId); BuildSqlParameter(sqlCmd, "@IngredientAdjustmentOriginalValue", SqlDbType.Float, originalValue); BuildSqlParameter(sqlCmd, "@IngredientAdjustmentNewValue", SqlDbType.Float, newValue); BuildSqlParameter(sqlCmd, "@IngredientAdjustmentMeasurementUnit", SqlDbType.SmallInt, measurementUnit); BuildSqlParameter(sqlCmd, "@IngredientAdjustmentRecipeIngredientId", SqlDbType.Int, recipeIngredientId); BuildSqlParameter(sqlCmd, "@IngredientAdjustmentWhen", SqlDbType.DateTime, when.Value); BuildSqlParameter(sqlCmd, "@IngredientAdjustmentId", SqlDbType.Int, ParameterDirection.ReturnValue); if (sqlCmd.ExecuteNonQuery() > 0) { result = new IngredientAdjustment(Convert.ToInt32(sqlCmd.Parameters["@IngredientAdjustmentId"].Value), employeeId, ingredientId, originalValue, newValue, measurementUnit, recipeIngredientId, when.Value); } } FinishedWithConnection(cn); return(result); }
public static IngredientAdjustment Get(int id) { IngredientAdjustment result = null; SqlConnection cn = GetConnection(); result = Get(cn, id); FinishedWithConnection(cn); return(result); }
private static IngredientAdjustment Get(SqlConnection cn, int id) { IngredientAdjustment result = null; using (SqlCommand cmd = new SqlCommand("SELECT * FROM IngredientAdjustment WHERE IngredientAdjustmentId=" + id, cn)) { using (SqlDataReader rdr = cmd.ExecuteReader()) { if (rdr.Read()) { result = BuildIngredientAdjustment(rdr); } } } return(result); }