예제 #1
0
        public async Task <bool> UpdateCouponCodeAsync(CouponCode coupon)
        {
            bool result = false;

            try
            {
                using (SqlConnection cnn = new SqlConnection(connectionStr))
                {
                    SqlCommand cmd = new SqlCommand("spUpdateCouponCode", cnn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Code", coupon.Code);
                    cmd.Parameters.AddWithValue("@OffPercent", coupon.OffPercent);
                    cmd.Parameters.AddWithValue("@StartDate", coupon.StartDate);
                    cmd.Parameters.AddWithValue("@EndDate", coupon.EndDate);
                    if (cnn.State == ConnectionState.Closed)
                    {
                        cnn.Open();
                    }
                    result = await cmd.ExecuteNonQueryAsync() > 0;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(result);
        }
예제 #2
0
        public async Task <CouponCode> FindCouponByCodeAsync(string code, DateTime?date = null)
        {
            CouponCode result = null;

            try
            {
                using (SqlConnection cnn = new SqlConnection(connectionStr))
                {
                    SqlCommand cmd = new SqlCommand("spFindCouponByCode", cnn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    if (date == null)
                    {
                        date = DateTime.Now;
                    }
                    cmd.Parameters.AddWithValue("@Code", code);
                    cmd.Parameters.AddWithValue("@Date", date);
                    if (cnn.State == ConnectionState.Closed)
                    {
                        cnn.Open();
                    }
                    using (SqlDataReader sdr = await cmd.ExecuteReaderAsync(CommandBehavior.SequentialAccess))
                    {
                        if (await sdr.ReadAsync())
                        {
                            result = new CouponCode {
                                Code = code.ToUpper()
                            };
                            result.OffPercent = sdr.GetInt32(sdr.GetOrdinal("OffPercent"));
                            result.StartDate  = sdr.GetDateTime(sdr.GetOrdinal("StartDate"));
                            result.EndDate    = sdr.GetDateTime(sdr.GetOrdinal("EndDate"));
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(result);
        }
예제 #3
0
 public virtual void Clear()
 {
     lineCollection.Clear();
     Coupon = new CouponCode();
 }
예제 #4
0
 public virtual void RemoveCoupon()
 {
     Coupon = new CouponCode();
 }