/// <summary> /// Add a new entry to the TicketDiscount table, for a TicketItem /// </summary> public static TicketDiscount Add(int discountId, YearId ticketPrimaryKey, int?ticketItemId, double?amount, int?pseudoEmployeeId) { TicketDiscount result = null; DateTime purchaseTime = DateTime.Now; SqlConnection cn = GetConnection(); string cmd = "AddTicketDiscount"; using (SqlCommand sqlCmd = new SqlCommand(cmd, cn)) { sqlCmd.CommandType = CommandType.StoredProcedure; BuildSqlParameter(sqlCmd, "@TicketDiscountYear", SqlDbType.SmallInt, ticketPrimaryKey.Year); BuildSqlParameter(sqlCmd, "@TicketDiscountDiscountId", SqlDbType.Int, discountId); BuildSqlParameter(sqlCmd, "@TicketDiscountTicketId", SqlDbType.Int, ticketPrimaryKey.Id); BuildSqlParameter(sqlCmd, "@TicketDiscountTicketItemId", SqlDbType.Int, ticketItemId); BuildSqlParameter(sqlCmd, "@TicketDiscountPseudoEmployeeId", SqlDbType.Int, pseudoEmployeeId); BuildSqlParameter(sqlCmd, "@TicketDiscountAmount", SqlDbType.Float, amount); BuildSqlParameter(sqlCmd, "@TicketDiscountId", SqlDbType.Int, ParameterDirection.ReturnValue); if (sqlCmd.ExecuteNonQuery() > 0) { result = new TicketDiscount( new YearId(ticketPrimaryKey.Year, Convert.ToInt32(sqlCmd.Parameters["@TicketDiscountId"].Value)), discountId, ticketPrimaryKey.Id, ticketItemId, amount, pseudoEmployeeId); } } FinishedWithConnection(cn); return(result); }
/// <summary> /// Update an entry in the TicketDiscount table /// </summary> public static bool Update(TicketDiscount ticketDiscount) { bool result = false; SqlConnection cn = GetConnection(); result = Update(cn, ticketDiscount); FinishedWithConnection(cn); return(result); }
/// <summary> /// Get an entry from the TicketDiscount table /// </summary> public static TicketDiscount Get(YearId primaryKey) { TicketDiscount result = null; SqlConnection cn = GetConnection(); result = Get(cn, primaryKey); FinishedWithConnection(cn); return(result); }
private static TicketDiscount Get(SqlConnection cn, YearId primaryKey) { TicketDiscount result = null; using (SqlCommand cmd = new SqlCommand("SELECT * FROM TicketDiscount WHERE TicketDiscountId=" + primaryKey.Id + " AND TicketDiscountYear=" + primaryKey.Year, cn)) { using (SqlDataReader rdr = cmd.ExecuteReader()) { if (rdr.Read()) { result = BuildTicketDiscount(rdr); } } } return(result); }
/// <summary> /// Delete an entry from the TicketDiscount table /// </summary> public static bool Delete(YearId primaryKey) { Int32 rowsAffected = 0; SqlConnection cn = GetConnection(); TicketDiscount ticketDiscount = Get(cn, primaryKey); if (ticketDiscount != null) { using (SqlCommand sqlCmd = cn.CreateCommand()) { sqlCmd.CommandText = "DELETE FROM TicketDiscount WHERE (TicketDiscountId=" + primaryKey.Id + " AND TicketDiscountYear=" + primaryKey.Year + ")"; rowsAffected = sqlCmd.ExecuteNonQuery(); } } FinishedWithConnection(cn); return(rowsAffected != 0); }
/// <summary> /// Get all the entries in the TicketDiscount table for the specified tickets /// </summary> public static IEnumerable <TicketDiscount> GetAllForTickets(IEnumerable <Ticket> tickets) { if (tickets != null) { foreach (Ticket ticket in tickets) { IEnumerable <TicketDiscount> discounts = TicketDiscount.GetAll(ticket.PrimaryKey); if (discounts == null) { continue; } foreach (TicketDiscount discount in discounts) { yield return(discount); } } } }
private static bool Update(SqlConnection cn, TicketDiscount ticketDiscount) { Int32 rowsAffected = 0; using (SqlCommand sqlCmd = cn.CreateCommand()) { sqlCmd.CommandText = "UPDATE TicketDiscount SET TicketDiscountDiscountId=@TicketDiscountDiscountId,TicketDiscountTicketId=@TicketDiscountTicketId,TicketDiscountTicketItemId=@TicketDiscountTicketItemId,TicketDiscountPseudoEmployeeId=@TicketDiscountPseudoEmployeeId,TicketDiscountAmount=@TicketDiscountAmount WHERE (TicketDiscountId=@TicketDiscountId AND TicketDiscountYear=@TicketDiscountYear)"; BuildSqlParameter(sqlCmd, "@TicketDiscountYear", SqlDbType.SmallInt, ticketDiscount.PrimaryKey.Year); BuildSqlParameter(sqlCmd, "@TicketDiscountId", SqlDbType.Int, ticketDiscount.PrimaryKey.Id); BuildSqlParameter(sqlCmd, "@TicketDiscountDiscountId", SqlDbType.Int, ticketDiscount.DiscountId); BuildSqlParameter(sqlCmd, "@TicketDiscountTicketId", SqlDbType.Int, ticketDiscount.TicketId); BuildSqlParameter(sqlCmd, "@TicketDiscountTicketItemId", SqlDbType.Int, ticketDiscount.TicketItemId); BuildSqlParameter(sqlCmd, "@TicketDiscountAmount", SqlDbType.Float, ticketDiscount.Amount); BuildSqlParameter(sqlCmd, "@TicketDiscountPseudoEmployeeId", SqlDbType.Int, ticketDiscount.PseudoEmployeeId); rowsAffected = sqlCmd.ExecuteNonQuery(); } return(rowsAffected != 0); }