protected void CouponCodeGoCommand(object sender, CommandEventArgs e) { string couponCode = CouponCodeEdit.Text; using (Database db = new MySqlDatabase()) { ClientInfo ci = db.GetClientInfo(Util.UserId); if (db.CheckActivationCode(couponCode)) { // Code is ok, raise the number of credits for this user db.MarkActivationCode(couponCode, Util.UserId); Config cfg = new Config(); cfg.Load(Server.MapPath("~/Config/trackprotect.config")); long prodid = 0; if (cfg["activationcode.productid"] != null) prodid = Convert.ToInt64(cfg["activationcode.productid"]); // Get the credits from the database ProductInfo pi = db.GetProductById(prodid); if (pi != null && pi.ProductId > 0) { // How many credits to issue string transactionIdCoupon = string.Format("COUPON {0}", couponCode); long orderId = db.CreateTransaction(Util.UserId, 0m, prodid, pi.Description); db.UpdateTransaction(orderId.ToString(), "OK", "OK", "Payment Completed", "COUPON", couponCode, couponCode, transactionIdCoupon, "COUPON", 0m, pi, "EUR", Util.GetCountryIso2(ci.Country)); db.UpdateUserCredits(Util.UserId, prodid, pi.Credits); db.AddCreditHistory(Util.UserId, prodid, pi.Credits, orderId); Response.Redirect(string.Format("~/Member/CouponSuccess.aspx?cradd={0}", pi.Credits), false); } } else { Response.Redirect(string.Format("~/Member/CouponFailure.aspx?couponcode={0}", couponCode), false); } } }