/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { try { int couponId = 0; int.TryParse(lblCouponId.Text, out couponId); Coupon coupon; if (couponId == 0) { coupon = new Coupon(); } else { coupon = new Coupon(couponId); } PercentOffCouponProvider percentOffCouponProvider = new PercentOffCouponProvider(); decimal percentOff = 0M; decimal.TryParse(txtPercentOff.Text, out percentOff); percentOffCouponProvider.PercentOff = percentOff; if (string.IsNullOrEmpty(txtCouponCode.Text)) { coupon.CouponCode = CoreUtility.GenerateRandomString(8); } else { coupon.CouponCode = txtCouponCode.Text; } DateTime expirationDate = DateTime.UtcNow; DateTime.TryParse(txtExpirationDate.Text, out expirationDate); coupon.ExpirationDate = expirationDate; coupon.IsSingleUse = chkIsSingleUse.Checked; coupon.Type = percentOffCouponProvider.GetType().AssemblyQualifiedName; coupon.ValueX = new Serializer().SerializeObject(percentOffCouponProvider, typeof(PercentOffCouponProvider)); coupon.Save(WebUtility.GetUserName()); Response.Redirect("~/admin/coupons.aspx", true); } catch (Exception ex) { Logger.Error(typeof(percentoffconfiguration).Name + ".btnSave_Click", ex); base.MasterPage.MessageCenter.DisplayCriticalMessage(ex.Message); } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void Page_Load(object sender, EventArgs e) { try { SetPercentOffConfigurationProperties(); couponId = Utility.GetIntParameter("couponId"); if (couponId > 0) { Coupon coupon = new Coupon(couponId); Serializer serializer = new Serializer(); PercentOffCouponProvider percentOffCouponProvider = serializer.DeserializeObject(coupon.ValueX, coupon.Type) as PercentOffCouponProvider; lblCouponId.Text = coupon.CouponId.ToString(); txtCouponCode.Text = coupon.CouponCode; txtExpirationDate.Text = coupon.ExpirationDate.ToString(); txtPercentOff.Text = percentOffCouponProvider.PercentOff.ToString(); chkIsSingleUse.Checked = coupon.IsSingleUse; } } catch (Exception ex) { Logger.Error(typeof(percentoffconfiguration).Name + ".Page_Load", ex); base.MasterPage.MessageCenter.DisplayCriticalMessage(ex.Message); } }