Exemplo n.º 1
0
        public void InsertCustomerPlan(CustomerPlan customerPlan)
        {
            Guard.NotNull(customerPlan, nameof(customerPlan));

            _customerPlanRepository.Insert(customerPlan);

            _requestCache.RemoveByPattern(CUSTOMERPLANS_PATTERN_KEY);
        }
Exemplo n.º 2
0
        public ActionResult Deposit(CustomerPlanModel customerPlanModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ViewBag.CurrencyCode = _workContext.WorkingCurrency.CurrencyCode;
                    PrepareCustomerPlanModel(customerPlanModel);
                    customerPlanModel.AvailableBalance = _customerService.GetAvailableBalance(_workContext.CurrentCustomer.Id);                    // _customerService.GetRepurchaseBalance(_workContext.CurrentCustomer.Id);

                    if (!CheckIfPositionExists(customerPlanModel.PlanId))
                    {
                        NotifyError("You require same level board position to buy this Ad Pack");
                        return(View(customerPlanModel));
                    }
                    if (customerPlanModel.PlanId != 30)
                    {
                        var noOfPack = _workContext.CurrentCustomer.Transaction.Where(x => x.RefId == customerPlanModel.PlanId - 1 && x.TranscationTypeId == 2 && x.StatusId == 2).Sum(x => x.NoOfPosition);
                        if (noOfPack < 10)
                        {
                            NotifyError("You require minimum 10 previous Ad Pack");
                            return(View(customerPlanModel));
                        }
                    }

                    if (customerPlanModel.PlanId > 0)
                    {
                        var plan = _planService.GetPlanById(customerPlanModel.PlanId);
                        var repurchasebalance = _customerService.GetAvailableBalance(_workContext.CurrentCustomer.Id);
                        var amountreq         = Convert.ToInt64(plan.MinimumInvestment) * ((customerPlanModel.NoOfPosition == 0) ? 1 : customerPlanModel.NoOfPosition);
                        if (customerPlanModel.ProcessorId == 5)
                        {
                            if (repurchasebalance < amountreq)
                            {
                                NotifyError("You do not have enough balance");
                                ViewBag.CurrencyCode = _workContext.WorkingCurrency.CurrencyCode;
                                PrepareCustomerPlanModel(customerPlanModel);
                                customerPlanModel.AvailableBalance = _customerService.GetAvailableBalance(_workContext.CurrentCustomer.Id);                                // _customerService.GetRepurchaseBalance(_workContext.CurrentCustomer.Id);
                                return(RedirectToAction("Deposit"));
                            }
                        }
                        TransactionModel transactionModel = new TransactionModel();
                        transactionModel.Amount            = amountreq;
                        transactionModel.CustomerId        = _workContext.CurrentCustomer.Id;
                        transactionModel.FinalAmount       = transactionModel.Amount;
                        transactionModel.NoOfPosition      = customerPlanModel.NoOfPosition;
                        transactionModel.TransactionDate   = DateTime.Now;
                        transactionModel.RefId             = plan.Id;
                        transactionModel.ProcessorId       = customerPlanModel.ProcessorId;
                        transactionModel.TranscationTypeId = (int)TransactionType.Purchase;
                        var transcation = transactionModel.ToEntity();

                        transcation.NoOfPosition = customerPlanModel.NoOfPosition;
                        if (customerPlanModel.ProcessorId == 5)
                        {
                            transcation.TranscationTypeId = (int)TransactionType.Purchase;
                            transcation.StatusId          = (int)Status.Completed;
                        }
                        else
                        {
                            transcation.StatusId          = (int)Status.Pending;
                            transcation.TranscationTypeId = (int)TransactionType.Purchase;
                        }
                        _transactionService.InsertTransaction(transcation);

                        for (int i = 0; i < transcation.NoOfPosition; i++)
                        {
                            var customerplan = new CustomerPlan();
                            customerplan.CustomerId     = transcation.CustomerId;
                            customerplan.PurchaseDate   = DateTime.Now;
                            customerplan.CreatedOnUtc   = DateTime.Now;
                            customerplan.UpdatedOnUtc   = DateTime.Now;
                            customerplan.PlanId         = plan.Id;
                            customerplan.AmountInvested = plan.MinimumInvestment;
                            customerplan.ROIToPay       = plan.MaximumInvestment;
                            customerplan.NoOfPayout     = 0;
                            customerplan.ExpiredDate    = DateTime.Today;
                            customerplan.IsActive       = true;
                            if (plan.StartROIAfterHours > 0)
                            {
                                customerplan.LastPaidDate = DateTime.Today.AddHours(plan.StartROIAfterHours);
                            }
                            else
                            {
                                customerplan.LastPaidDate = DateTime.Today;
                            }
                            _customerPlanService.InsertCustomerPlan(customerplan);
                        }
                        if (customerPlanModel.ProcessorId == 5)
                        {
                            NotifySuccess("Your purchase was successfull");
                            ReleaseLevelCommission(plan.Id, _workContext.CurrentCustomer.Id, transactionModel.Amount);
                        }
                        else
                        {
                            int           value         = customerPlanModel.ProcessorId;
                            PaymentMethod paymentmethod = (PaymentMethod)value;

                            ViewBag.SaveSuccess              = true;
                            customerPlanModel.Id             = plan.Id;
                            customerPlanModel.PlanName       = plan.Name;
                            customerPlanModel.ProcessorName  = paymentmethod.ToString();
                            customerPlanModel.PaymentMethod  = paymentmethod;
                            customerPlanModel.TransactionId  = transcation.Id;
                            customerPlanModel.AmountInvested = (decimal)transactionModel.Amount;
                            return(RedirectToAction("ConfirmPayment", customerPlanModel));
                        }
                    }
                    else
                    {
                        NotifyError("Please select Package");
                    }
                }
            }
            catch (Exception ex)
            {
                ViewBag.SaveSuccess = false;
                NotifyError(T("Invesment.Deposit.FundingError"));
            }
            ViewBag.CurrencyCode = _workContext.WorkingCurrency.CurrencyCode;
            customerPlanModel.AvailableBalance = _customerService.GetAvailableBalance(_workContext.CurrentCustomer.Id);            // _customerService.GetRepurchaseBalance(_workContext.CurrentCustomer.Id);
            PrepareCustomerPlanModel(customerPlanModel);
            return(View(customerPlanModel));
        }
Exemplo n.º 3
0
        public void UpdateCustomerPlan(CustomerPlan customerPlan)
        {
            Guard.NotNull(customerPlan, nameof(customerPlan));

            _customerPlanRepository.Update(customerPlan);
        }
Exemplo n.º 4
0
 public void DeleteCustomerPlan(CustomerPlan customerPlan)
 {
     Guard.NotNull(customerPlan, nameof(customerPlan));
     customerPlan.Deleted = true;
     _customerPlanRepository.Update(customerPlan);
 }