Example #1
0
        protected void SaveCoupon()
        {
            if (ValidateData())
            {
                try
                {
                    Coupon coupon = CouponService.GetCoupon(CouponId);
                    coupon.Code              = txtCode.Text;
                    coupon.Value             = float.Parse(txtValue.Text.Replace(".", ","));
                    coupon.Type              = (CouponType)Enum.Parse(typeof(CouponType), ddlCouponType.SelectedValue);
                    coupon.ExpirationDate    = txtExpirationDate.Text.IsNotEmpty() ? (DateTime?)DateTime.Parse(txtExpirationDate.Text).AddHours(23).AddMinutes(59).AddSeconds(59) : null;
                    coupon.PossibleUses      = int.Parse(txtPosibleUses.Text);
                    coupon.MinimalOrderPrice = float.Parse(txtMinimalOrderPrice.Text.Replace(".", ","));
                    coupon.Enabled           = chkEnabled.Checked;
                    CouponService.UpdateCoupon(coupon);

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


                    CouponService.DeleteAllProductsFromCoupon(CouponId);
                    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 + " SaveCoupon");
                    Debug.LogError(ex);
                }
            }
        }