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); } } }
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); } } }