Пример #1
0
    protected void BuyProduct_Click(object sender, EventArgs e)
    {
        ErrorMessage.Text         = string.Empty;
        ErrorMessagePanel.Visible = false;

        try
        {
            int    productId       = Convert.ToInt32(((Button)sender).CommandArgument);
            int    quantity        = Convert.ToInt32(ProductInfoBuyCount.Text);
            string deliveryAddress = InputChecker.HtmlEncode(DeliveryAddressTextBox.Text, DeliveryAddressTextBox.MaxLength, U6005.DELIVERYADDRESS);
            string email           = EmailTextBox.Text.Trim();
            int?   promotorId      = (int?)Session["MarketplacePromotorId"];

            MarketplaceProduct product = new MarketplaceProduct(productId);

            if (Member.IsLogged)
            {
                Member buyer = user;

                if (!product.IsGeolocationMeet(buyer))
                {
                    throw new MsgException("You don't meet Geolocation constraints for this product.");
                }

                if (buyer.Id == product.SellerId)
                {
                    throw new MsgException(U5006.BUYFROMYOURSELF);
                }
            }

            if (quantity > product.Quantity)
            {
                throw new MsgException(U5006.SELLERDOESNTHAVEENOUGHT);
            }

            if (AppSettings.Marketplace.MarketplaceAllowPurchaseFromPaymentProcessors)
            {
                string username = Member.IsLogged ? user.Name : MarketplaceMember.AnonymousUsername;

                PaymentProcessorButtonsPlaceHolder.Visible = true;
                var bg = new BuyMarketplaceProductButtonGenerator(username, productId, quantity, deliveryAddress, email, promotorId);
                PaymentButtons.Text = GenerateHTMLButtons.GetPaymentButtons(bg);
            }
            if (Member.IsLogged && AppSettings.Marketplace.MarketplaceAllowPurchaseFromAdBalance)
            {
                BuyProductFromAdBalance.Visible = true;
            }
            if (Member.IsLogged && AppSettings.Marketplace.AllowPurchaseFromMarketplaceBalance)
            {
                BuyProductFromMarketplaceBalance.Visible = true;
            }
            BuyProductButton.Visible = false;
        }
        catch (MsgException ex)
        {
            ErrorMessage.Text         = ex.Message;
            ErrorMessagePanel.Visible = true;
        }
        catch (Exception ex)
        {
            ErrorLogger.Log(ex);
        }
    }