void button_Click(object sender, CommandEventArgs e) { CodeSubmitedPanel.Visible = true; GiftCode Code = new GiftCode(Convert.ToInt32(e.CommandArgument)); try { Member User = Member.Current; Int32 Price = GiftCodeExchangeRate.GetPrice(User, Code.Id); if (Price < 0) { throw new MsgException("You are not eligible for this code"); } //Activity check if (!Code.IsActiveAtTheMoment(User)) { throw new MsgException("This card/code is disabled"); } //Check if member is not banned meantime if (User.IsBanned) { Member.Current.Logout(Response); FormsAuthentication.SignOut(); Session.Abandon(); Response.Redirect("~/status.aspx?type=logoutsuspended&id=logoutsus"); } //Balance check if (Price > User.PointsBalance) { throw new MsgException(L1.NOTENOUGHFUNDS); } //Send the request & take the money GiftCodeRequest.Add(User, Code.Id, Price); } catch (MsgException ex) { SuccPanel.Visible = false; ErrorPanel.Visible = true; ErrorMessage.Text = ex.Message; } }
/// <summary> /// Adds the request, takes the Points too /// </summary> /// <param name="userId"></param> /// <param name="giftCodeId"></param> /// <param name="pointsPaid"></param> public static void Add(Member user, int giftCodeId, int pointsPaid) { //Take points user.SubtractFromPointsBalance(pointsPaid, "Gift Code"); user.TotalPointsExchanged += pointsPaid; user.Save(); //Add GiftCodeRequest Target = new GiftCodeRequest(); Target.UserId = user.Id; Target.GiftCodeId = giftCodeId; Target.DateRequested = DateTime.Now; Target.Status = GiftCodeRequestStatus.Pending; Target.DateSent = DateTime.Now; Target.CodeSent = ""; Target.PointsPaid = pointsPaid; Target.Save(); //Points generated stats ApplyToStats(pointsPaid); }