示例#1
0
    protected void BuyOrUpgradePlan(PurchaseBalances balance)
    {
        try
        {
            var plan        = new InvestmentPlatformPlan(int.Parse(PlansDropDownList.SelectedValue));
            var activePlans = CurrentMode == InvestmentPlatformMode.Levels ? 0 : userActivePlans.Count;

            if (AppSettings.InvestmentPlatform.LevelsEnabled)
            {
                InvestmentLevelsManager.CanUserDepositOnLevel(plan, User);
            }

            if (plan.MaxPrice > Money.Zero)
            {
                if (AppSettings.InvestmentPlatform.InvestmentPlatformPlansPolicy == PlansPolicy.OneUpgradedPlan)
                {
                    throw new MsgException(U6012.CANTUPGRADERANGEPLAN);
                }

                var targetPrice = Money.Parse(RangePriceTextBox.Text);
                if (plan.CheckPlanPrice(targetPrice))
                {
                    InvestmentPlatformManager.BuyOrUpgradePlan(Member.Current, balance, plan, targetPrice);
                }
                else
                {
                    throw new MsgException(U6012.TYPECORRECTPRICE);
                }
            }
            else
            {
                InvestmentPlatformManager.BuyOrUpgradePlan(Member.Current, balance, plan);
            }

            //IF activePlans = 1, MEANS THAT WE UPGRADE PLAN (ON PlansPolicy.OneUpgradedPlan)
            if (AppSettings.InvestmentPlatform.InvestmentPlatformPlansPolicy == PlansPolicy.OneUpgradedPlan && activePlans == 1)
            {
                SuccessTextLiteral.Text = string.Format(U6011.SUCCESSUPGRADEPLAN, plan.Name);
            }
            else
            {
                SuccessTextLiteral.Text = string.Format(U6006.SUCCESBOUGHTPLAN, plan.Name);
            }

            SuccessPanel.Visible = true;

            availablePlans = InvestmentPlatformManager.GetAllAvailablePlansForUser(User.Id);
            InitBuyViewControls();
            InitPlans();
        }
        catch (Exception ex)
        {
            ErrorPanel.Visible    = true;
            ErrorTextLiteral.Text = ex.Message;
            if (!(ex is MsgException))
            {
                ErrorLogger.Log(ex);
            }
        }
    }
示例#2
0
        protected void BuyInvestmentPlatformPlan(Member user, Money amount, InvestmentPlatformPlan plan, string from, string transId, string cryptoCurrencyInfo)
        {
            bool successful = false;

            try
            {
                if (plan.MaxPrice > Money.Zero)
                {
                    if (!plan.CheckPlanPrice(amount))
                    {
                        throw new MsgException("Not enough money sent!");
                    }

                    InvestmentPlatformManager.BuyOrUpgradePlan(user, PurchaseBalances.PaymentProcessor, plan, amount);
                    successful = true;
                }
                else
                {
                    var price = plan.Price;

                    if (AppSettings.InvestmentPlatform.LevelsEnabled)
                    {
                        price += plan.LevelFee;
                    }

                    if (amount < price)
                    {
                        throw new MsgException("Not enough money sent!");
                    }

                    InvestmentPlatformManager.BuyOrUpgradePlan(user, PurchaseBalances.PaymentProcessor, plan);
                    successful = true;
                }
            }
            catch (Exception ex)
            {
                successful = false;
                ErrorLogger.Log(ex);
            }

            PaymentProcessor PP = PaymentAccountDetails.GetFromStringType(from);

            CompletedPaymentLog.Create(PP, "Investment Plan", transId, false, user.Name, amount, Money.Zero, successful, cryptoCurrencyInfo);
        }