Exemplo n.º 1
0
        protected void CreateCoupon()
        {
            if (ValidateData())
            {
                try
                {
                    var coupon = new Coupon()
                        {
                            Code = txtCode.Text,
                            Enabled = chkEnabled.Checked,
                            Type = (CouponType)Enum.Parse(typeof(CouponType), ddlCouponType.SelectedValue),
                            Value = float.Parse(txtValue.Text.Replace(".", ",")),
                            ExpirationDate =
                                txtExpirationDate.Text.IsNotEmpty()
                                    ? (DateTime?)DateTime.Parse(txtExpirationDate.Text).AddHours(23).AddMinutes(59).AddSeconds(59)
                                    : null,
                            PossibleUses = int.Parse(txtPosibleUses.Text),
                            MinimalOrderPrice = float.Parse(txtMinimalOrderPrice.Text.Replace(".", ",")),
                            ActualUses = 0,
                            AddingDate = DateTime.Now,
                        };

                    CouponService.AddCoupon(coupon);

                    if (ViewState["SelectedCategories"] != null)
                    {
                        List<int> list = (List<int>)ViewState["SelectedCategories"];
                        foreach (var catID in list)
                        {
                            CouponService.AddCategoryToCoupon(coupon.CouponID, catID);
                        }
                    }

                    List<int> listproducts = (List<int>)ViewState["SelectedProducts"];
                    if (listproducts != null)
                    {
                        foreach (var productid in listproducts)
                        {
                            CouponService.AddProductToCoupon(coupon.CouponID, productid);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MsgErr(ex.Message + " CreateCoupon main");
                    Debug.LogError(ex);
                }
            }
        }
Exemplo n.º 2
0
 public static void AddCoupon(Coupon coupon)
 {
     coupon.CouponID = SQLDataAccess.ExecuteScalar<int>(" INSERT INTO [Catalog].[Coupon] " +
                               " ([Code], [Type], [Value], [AddingDate], [ExpirationDate], [PossibleUses], [ActualUses], [Enabled], [MinimalOrderPrice]) " +
                               " VALUES (@Code, @Type, @Value, @AddingDate, @ExpirationDate, @PossibleUses, @ActualUses, @Enabled, @MinimalOrderPrice); SELECT SCOPE_IDENTITY();",
                               CommandType.Text,
                               new SqlParameter("@Code", coupon.Code),
                               new SqlParameter("@Type", coupon.Type),
                               new SqlParameter("@Value", coupon.Value),
                               new SqlParameter("@AddingDate", coupon.AddingDate),
                               new SqlParameter("@ExpirationDate", coupon.ExpirationDate ?? (object)DBNull.Value),
                               new SqlParameter("@PossibleUses", coupon.PossibleUses),
                               new SqlParameter("@ActualUses", coupon.ActualUses),
                               new SqlParameter("@Enabled", coupon.Enabled),
                               new SqlParameter("@MinimalOrderPrice", coupon.MinimalOrderPrice)
                               );
 }
Exemplo n.º 3
0
 public static void UpdateCoupon(Coupon coupon)
 {
     SQLDataAccess.ExecuteNonQuery(" UPDATE [Catalog].[Coupon] SET [Code] = @Code, [Type] = @Type, [Value] = @Value, [AddingDate]=@AddingDate, [ExpirationDate] = @ExpirationDate, [PossibleUses] = @PossibleUses, [ActualUses] = @ActualUses, [Enabled] = @Enabled, [MinimalOrderPrice] = @MinimalOrderPrice " +
             " WHERE CouponID = @CouponID", CommandType.Text,
             new SqlParameter("@CouponID", coupon.CouponID),
             new SqlParameter("@Code", coupon.Code),
             new SqlParameter("@Type", coupon.Type),
             new SqlParameter("@Value", coupon.Value),
             new SqlParameter("@AddingDate", coupon.AddingDate),
             new SqlParameter("@ExpirationDate", coupon.ExpirationDate ?? (object)DBNull.Value),
             new SqlParameter("@PossibleUses", coupon.PossibleUses),
             new SqlParameter("@ActualUses", coupon.ActualUses),
             new SqlParameter("@Enabled", coupon.Enabled),
             new SqlParameter("@MinimalOrderPrice", coupon.MinimalOrderPrice)
             );
 }