示例#1
0
    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;
        }
    }
示例#2
0
    public static List <KeyValuePair <GiftCode, int> > GetActiveCodesForMember(Member user, int giftCardId)
    {
        //Codes active
        var where = TableHelper.MakeDictionary("GiftCardId", giftCardId);
        where.Add("Status", (int)BaseStatus.Active);
        var result = TableHelper.SelectRows <GiftCode>(where);

        var list = new List <KeyValuePair <GiftCode, int> >();

        foreach (var code in result)
        {
            int price = GiftCodeExchangeRate.GetPrice(user, code.Id);
            if (price != -1)
            {
                list.Add(new KeyValuePair <GiftCode, int>(code, price));
            }
        }

        return(list);
    }