Пример #1
0
        public bool ApplyToTicket()
        {
            int catCount  = CouponCategory.Count(Id);
            int itemCount = CouponItem.Count(Id);

            return(catCount + itemCount == 0);
        }
Пример #2
0
        /// <summary>
        /// Update an entry in the CouponCategory table
        /// </summary>
        public static bool Update(CouponCategory couponCategory)
        {
            bool result = false;

            SqlConnection cn = GetConnection();

            result = Update(cn, couponCategory);
            FinishedWithConnection(cn);
            return(result);
        }
Пример #3
0
        /// <summary>
        /// Get an entry from the CouponCategory table
        /// </summary>
        public static CouponCategory Get(int id)
        {
            CouponCategory result = null;

            SqlConnection cn = GetConnection();

            result = Get(cn, id);
            FinishedWithConnection(cn);
            return(result);
        }
Пример #4
0
        private static bool Update(SqlConnection cn, CouponCategory couponCategory)
        {
            Int32 rowsAffected = 0;

            using (SqlCommand sqlCmd = cn.CreateCommand())
            {
                sqlCmd.CommandText = "UPDATE CouponCategory SET CouponCategoryCouponId=@CouponCategoryCouponId,CouponCategoryCategoryId=@CouponCategoryCategoryId WHERE CouponCategoryId=@CouponCategoryId";

                BuildSqlParameter(sqlCmd, "@CouponCategoryId", SqlDbType.Int, couponCategory.Id);
                BuildSqlParameter(sqlCmd, "@CouponCategoryCouponId", SqlDbType.Int, couponCategory.CouponId);
                BuildSqlParameter(sqlCmd, "@CouponCategoryCategoryId", SqlDbType.Int, couponCategory.CategoryId);

                rowsAffected = sqlCmd.ExecuteNonQuery();
            }
            return(rowsAffected != 0);
        }
Пример #5
0
        private static CouponCategory Get(SqlConnection cn, int id)
        {
            CouponCategory result = null;

            using (SqlCommand cmd = new SqlCommand("SELECT * FROM CouponCategory WHERE CouponCategoryId=" + id, cn))
            {
                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        result = BuildCouponCategory(rdr);
                    }
                }
            }
            return(result);
        }
Пример #6
0
        /// <summary>
        /// Delete an entry from the CouponCategory table
        /// </summary>
        public static bool Delete(int id)
        {
            Int32          rowsAffected   = 0;
            SqlConnection  cn             = GetConnection();
            CouponCategory couponCategory = Get(cn, id);

            if (couponCategory != null)
            {
                using (SqlCommand sqlCmd = cn.CreateCommand())
                {
                    sqlCmd.CommandText = "DELETE FROM CouponCategory WHERE CouponCategoryId=" + id;
                    rowsAffected       = sqlCmd.ExecuteNonQuery();
                }
            }
            FinishedWithConnection(cn);
            return(rowsAffected != 0);
        }
Пример #7
0
        /// <summary>
        /// Add a new entry to the CouponCategory table
        /// </summary>
        public static CouponCategory Add(int couponId, int categoryId)
        {
            CouponCategory result = null;

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

            using (SqlCommand sqlCmd = new SqlCommand(cmd, cn))
            {
                sqlCmd.CommandType = CommandType.StoredProcedure;
                BuildSqlParameter(sqlCmd, "@CouponCategoryCouponId", SqlDbType.Int, couponId);
                BuildSqlParameter(sqlCmd, "@CouponCategoryCategoryId", SqlDbType.Int, categoryId);
                BuildSqlParameter(sqlCmd, "@CouponCategoryId", SqlDbType.Int, ParameterDirection.ReturnValue);
                if (sqlCmd.ExecuteNonQuery() > 0)
                {
                    result = new CouponCategory(Convert.ToInt32(sqlCmd.Parameters["@CouponCategoryId"].Value),
                                                couponId, categoryId);
                }
            }
            FinishedWithConnection(cn);
            return(result);
        }