private static Coupon CreateCoupon(IDataReader reader) { //Get the coupon type id. int couponTypeId = reader.GetInt32(reader.GetOrdinal("CouponTypeId")); CouponType couponType = CouponType.GetCouponType(couponTypeId); //Get an XmlReader for the XmlData string xmlString = reader.GetString(reader.GetOrdinal("XmlData")); System.IO.StringReader rdr = new System.IO.StringReader(xmlString); XmlReader xmlData = XmlReader.Create(rdr); //Deserialize the Xml to the object. XmlSerializer serializer = new XmlSerializer(couponType.CouponClassType); Coupon newCoupon = (Coupon)serializer.Deserialize(xmlData); //Load the common properties. newCoupon._couponCode = reader.GetString(reader.GetOrdinal("CouponCode")); newCoupon._couponType = couponType; newCoupon._isSingleUse = reader.GetBoolean(reader.GetOrdinal("IsSingleUse")); newCoupon._numUses = reader.GetInt32(reader.GetOrdinal("NumberUses")); //the following is a stupid hack. //it seems to me that a nullable type should just convert from DbNull ... if (reader["ExpirationDate"] != DBNull.Value) { newCoupon._expirationDate = (DateTime?)reader["ExpirationDate"]; } if (reader["UserId"] != DBNull.Value) { newCoupon._userId = (Guid?)reader["UserId"]; } return(newCoupon); }
private void EditCouponType(int couponTypeId) { Commerce.Promotions.CouponType selectedCouponType = Commerce.Promotions.CouponType.GetCouponType(couponTypeId); lblID.Text = selectedCouponType.CouponTypeID.ToString(); txtDescription.Text = selectedCouponType.Description; txtClassName.Text = selectedCouponType.CouponClassType.FullName; couponTypeEditPanel.Visible = true; }
private static CouponType CreateCouponTypeFromReader(IDataReader rdr) { CouponType newType = new CouponType( rdr.GetInt32(rdr.GetOrdinal("CouponTypeId")), rdr.GetString(rdr.GetOrdinal("Description")), rdr.GetString(rdr.GetOrdinal("ProcessingClassName"))); //Add to the cache. _couponTypes.Add(newType.CouponTypeID, newType); return(newType); }
protected void btnSave_Click(object sender, EventArgs e) { if (!Page.IsValid) { //no save ... exit. return; } string classTypeName = BuildFullClassName(); try { if (!String.IsNullOrEmpty(lblID.Text)) { //Edit on the coupon type. int couponTypeId; if (int.TryParse(lblID.Text, out couponTypeId)) { Commerce.Promotions.CouponType selectedCouponType = Commerce.Promotions.CouponType.GetCouponType(couponTypeId); selectedCouponType.Description = txtDescription.Text; selectedCouponType.CouponClassType = System.Web.Compilation.BuildManager.GetType(classTypeName, true); selectedCouponType.Save(); } } else { //this is a new coupon type. Commerce.Promotions.CouponType couponType = new Commerce.Promotions.CouponType( -1, txtDescription.Text.Trim(), classTypeName); couponType.Save(); } lblMessage.ForeColor = System.Drawing.Color.LightSteelBlue; lblMessage.Text = "Coupon Type Saved"; couponTypeEditPanel.Visible = false; BindCouponTypes(); } catch (Exception ex) { lblMessage.ForeColor = System.Drawing.Color.Red; lblMessage.Text = "Save failed<br/>" + ex.Message; } }
protected Coupon(string couponCode, CouponType couponType) { _couponCode = couponCode; _couponType = couponType; }
public void NewCoupon(Commerce.Promotions.CouponType cpnType) { btnGenerate.Visible = true; ViewState["CouponTypeId"] = cpnType.CouponTypeID; ViewState["IsNew"] = true; }
public PercentOffCoupon(string couponCode, CouponType couponType) : base(couponCode, couponType) { }