/// <summary> /// Add a new entry to the VendorOrderItem table /// </summary> public static VendorOrderItem Add(int vendorOrderId, int vendorItemId, int quantity) { VendorOrderItem result = null; quantity = quantity.Clamp(1, short.MaxValue); SqlConnection cn = GetConnection(); string cmd = "AddVendorOrderItem"; using (SqlCommand sqlCmd = new SqlCommand(cmd, cn)) { sqlCmd.CommandType = CommandType.StoredProcedure; BuildSqlParameter(sqlCmd, "@VendorOrderItemVendorOrderId", SqlDbType.Int, vendorOrderId); BuildSqlParameter(sqlCmd, "@VendorOrderItemVendorItemId", SqlDbType.Int, vendorItemId); BuildSqlParameter(sqlCmd, "@VendorOrderItemQuantity", SqlDbType.Int, quantity); BuildSqlParameter(sqlCmd, "@VendorOrderItemId", SqlDbType.Int, ParameterDirection.ReturnValue); if (sqlCmd.ExecuteNonQuery() > 0) { result = new VendorOrderItem(Convert.ToInt32(sqlCmd.Parameters["@VendorOrderItemId"].Value), vendorOrderId, vendorItemId, quantity); } } FinishedWithConnection(cn); return(result); }
/// <summary> /// Update an entry in the VendorOrderItem table /// </summary> public static bool Update(VendorOrderItem vendorOrderItem) { bool result = false; SqlConnection cn = GetConnection(); result = Update(cn, vendorOrderItem); FinishedWithConnection(cn); return(result); }
/// <summary> /// Get an entry from the VendorOrderItem table /// </summary> public static VendorOrderItem Get(int id) { VendorOrderItem result = null; SqlConnection cn = GetConnection(); result = Get(cn, id); FinishedWithConnection(cn); return(result); }
private static VendorOrderItem Get(SqlConnection cn, int id) { VendorOrderItem result = null; using (SqlCommand cmd = new SqlCommand("SELECT * FROM VendorOrderItem WHERE VendorOrderItemId=" + id, cn)) { using (SqlDataReader rdr = cmd.ExecuteReader()) { if (rdr.Read()) { result = BuildVendorOrderItem(rdr); } } } return(result); }
private static bool Update(SqlConnection cn, VendorOrderItem vendorOrderItem) { Int32 rowsAffected = 0; using (SqlCommand sqlCmd = cn.CreateCommand()) { sqlCmd.CommandText = "UPDATE VendorOrderItem SET VendorOrderItemVendorOrderId=@VendorOrderItemVendorOrderId,VendorOrderItemVendorItemId=@VendorOrderItemVendorItemId,VendorOrderItemQuantity=@VendorOrderItemQuantity WHERE VendorOrderItemId=@VendorOrderItemId"; BuildSqlParameter(sqlCmd, "@VendorOrderItemId", SqlDbType.Int, vendorOrderItem.Id); BuildSqlParameter(sqlCmd, "@VendorOrderItemVendorOrderId", SqlDbType.Int, vendorOrderItem.VendorOrderId); BuildSqlParameter(sqlCmd, "@VendorOrderItemVendorItemId", SqlDbType.Int, vendorOrderItem.VendorItemId); BuildSqlParameter(sqlCmd, "@VendorOrderItemQuantity", SqlDbType.Int, vendorOrderItem.Quantity); rowsAffected = sqlCmd.ExecuteNonQuery(); } return(rowsAffected != 0); }
/// <summary> /// Delete an entry from the VendorOrderItem table /// </summary> public static bool Delete(int id) { Int32 rowsAffected = 0; SqlConnection cn = GetConnection(); VendorOrderItem vendorOrderItem = Get(cn, id); if (vendorOrderItem != null) { using (SqlCommand sqlCmd = cn.CreateCommand()) { sqlCmd.CommandText = "DELETE FROM VendorOrderItem WHERE VendorOrderItemId=" + id; rowsAffected = sqlCmd.ExecuteNonQuery(); } } FinishedWithConnection(cn); return(rowsAffected != 0); }