示例#1
0
        /// <summary>
        /// Add a new entry to the TicketCoupon table, for a Ticket
        /// </summary>
        public static TicketCoupon AddForTicket(int couponId, YearId ticketPrimaryKey)
        {
            TicketCoupon result = null;

            SqlConnection cn  = GetConnection();
            string        cmd = "AddTicketCoupon";

            using (SqlCommand sqlCmd = new SqlCommand(cmd, cn))
            {
                sqlCmd.CommandType = CommandType.StoredProcedure;
                BuildSqlParameter(sqlCmd, "@TicketCouponYear", SqlDbType.SmallInt, ticketPrimaryKey.Year);
                BuildSqlParameter(sqlCmd, "@TicketCouponCouponId", SqlDbType.Int, couponId);
                BuildSqlParameter(sqlCmd, "@TicketCouponTicketId", SqlDbType.Int, ticketPrimaryKey.Id);
                BuildSqlParameter(sqlCmd, "@TicketCouponTicketItemId", SqlDbType.Int, null);
                BuildSqlParameter(sqlCmd, "@TicketCouponId", SqlDbType.Int, ParameterDirection.ReturnValue);
                if (sqlCmd.ExecuteNonQuery() > 0)
                {
                    result = new TicketCoupon(
                        new YearId(ticketPrimaryKey.Year,
                                   Convert.ToInt32(sqlCmd.Parameters["@TicketCouponId"].Value)),
                        couponId, ticketPrimaryKey.Id, 0);
                }
            }
            FinishedWithConnection(cn);
            return(result);
        }
示例#2
0
        /// <summary>
        /// Update an entry in the TicketCoupon table
        /// </summary>
        public static bool Update(TicketCoupon ticketCoupon)
        {
            bool result = false;

            SqlConnection cn = GetConnection();

            result = Update(cn, ticketCoupon);
            FinishedWithConnection(cn);

            return(result);
        }
示例#3
0
        /// <summary>
        /// Get an entry from the TicketCoupon table
        /// </summary>
        public static TicketCoupon Get(YearId primaryKey)
        {
            TicketCoupon result = null;

            SqlConnection cn = GetConnection();

            result = Get(cn, primaryKey);
            FinishedWithConnection(cn);

            return(result);
        }
示例#4
0
        private static TicketCoupon Get(SqlConnection cn, YearId primaryKey)
        {
            TicketCoupon result = null;

            using (SqlCommand cmd = new SqlCommand("SELECT * FROM TicketCoupon WHERE (TicketCouponId=" + primaryKey.Id + " AND TicketCouponYear=" + primaryKey.Year + ")", cn))
            {
                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        result = BuildTicketCoupon(rdr);
                    }
                }
            }
            return(result);
        }
示例#5
0
        /// <summary>
        /// Delete an entry from the TicketCoupon table
        /// </summary>
        public static bool Delete(YearId primaryKey)
        {
            Int32         rowsAffected = 0;
            SqlConnection cn           = GetConnection();
            TicketCoupon  ticketCoupon = Get(cn, primaryKey);

            if (ticketCoupon != null)
            {
                using (SqlCommand sqlCmd = cn.CreateCommand())
                {
                    sqlCmd.CommandText = "DELETE FROM TicketCoupon WHERE (TicketCouponId=" + primaryKey.Id + " AND TicketCouponYear=" + primaryKey.Year + ")";
                    rowsAffected       = sqlCmd.ExecuteNonQuery();
                }
            }
            FinishedWithConnection(cn);
            return(rowsAffected != 0);
        }
示例#6
0
        private static bool Update(SqlConnection cn, TicketCoupon ticketCoupon)
        {
            Int32 rowsAffected = 0;

            using (SqlCommand sqlCmd = cn.CreateCommand())
            {
                sqlCmd.CommandText = "UPDATE TicketCoupon SET TicketCouponCouponId=@TicketCouponCouponId,TicketCouponTicketId=@TicketCouponTicketId,TicketCouponTicketItemId=@TicketCouponTicketItemId WHERE (TicketCouponId=@TicketCouponId AND TicketCouponYear=@TicketCouponYear)";

                BuildSqlParameter(sqlCmd, "@TicketCouponYear", SqlDbType.Int, ticketCoupon.PrimaryKey.Year);
                BuildSqlParameter(sqlCmd, "@TicketCouponId", SqlDbType.Int, ticketCoupon.PrimaryKey.Id);
                BuildSqlParameter(sqlCmd, "@TicketCouponCouponId", SqlDbType.Int, ticketCoupon.CouponId);
                BuildSqlParameter(sqlCmd, "@TicketCouponTicketId", SqlDbType.Int, ticketCoupon.TicketId);
                BuildSqlParameter(sqlCmd, "@TicketCouponTicketItemId", SqlDbType.Int, ticketCoupon.TicketItemId);

                rowsAffected = sqlCmd.ExecuteNonQuery();
            }
            return(rowsAffected != 0);
        }
示例#7
0
 /// <summary>
 /// Get all the entries in the TicketCoupon table for a specififc tickets
 /// </summary>
 public static IEnumerable <TicketCoupon> GetAllForTickets(IEnumerable <Ticket> tickets)
 {
     if (tickets != null)
     {
         foreach (Ticket ticket in tickets)
         {
             IEnumerable <TicketCoupon> coupons = TicketCoupon.GetAll(ticket.PrimaryKey);
             if (coupons == null)
             {
                 continue;
             }
             foreach (TicketCoupon coupon in coupons)
             {
                 yield return(coupon);
             }
         }
     }
 }