public async Task <InvestmentTargetModel> AddInvestmentTarget(InvestmentTargetModel investmentTargetModel) { InvestmentTarget investmentTarget = _mapper.Map <InvestmentTarget>(investmentTargetModel); var addedInvestmentTarget = await _investmentTargetManager.AddInvestmentTarget(investmentTarget); return(_mapper.Map <InvestmentTargetModel>(addedInvestmentTarget)); }
public async Task <IActionResult> New() { if (!_userService.IsSignedIn(User)) { return(RedirectToAction(nameof(HomeController.Index), "Home")); } var config = await _globalConfigurationService.GetValueConfig(Constants.Configuration.ProgramLocked); if (config.Contains("true")) { return(View("~/Views/Lock.cshtml")); } var currentUser = await _userService.GetCurrentUser(); var model = new InvestmentTargetModel() { Duration = Common.Duration.TwelfthMonth, Frequency = Common.Frequency.OneWeek, User = currentUser }; return(View(model)); }
public async Task DeleteInvestmentTarget(InvestmentTargetModel investmentTargetModel) { InvestmentTarget investmentTarget = _mapper.Map <InvestmentTarget>(investmentTargetModel); await _investmentTargetManager.DeleteInvestmentTarget(investmentTarget); }
public async Task <IActionResult> New(InvestmentTargetModel model) { if (!_userService.IsSignedIn(User)) { return(RedirectToAction(nameof(HomeController.Index), "Home")); } var config = await _globalConfigurationService.GetValueConfig(Constants.Configuration.ProgramLocked); if (config.Contains("true")) { return(View("~/Views/Lock.cshtml")); } var currentUser = await _userService.GetCurrentUser(); model.User = currentUser; if (ModelState.IsValid) { if (model.ExpectedAmount == null) { ModelState.AddModelError("ExpectedAmount", string.Format(ValidationMessages.FieldEmpty, Model.Resources.Common.ExpectedAmount)); } else if (model.ExpectedAmount < _configuration.GetValue <decimal>("InvestmentValidation:MinTargetAmount")) { ModelState.AddModelError("ExpectedAmount", string.Format(ValidationMessages.InvestmentTargetAmountInvalid, _configuration.GetValue <decimal>("InvestmentValidation:MinTargetAmount"))); } else if (model.ExpectedAmount <= currentUser.CurrentAccountAmount) { ModelState.AddModelError("ExpectedAmount", ValidationMessages.InvestmentTargetAmountInvalid2); } else { var oneTimeAmount = await OneTimeAmount((decimal)model.ExpectedAmount, (int)model.Duration, (int)model.Frequency); if (oneTimeAmount <= 0) { ModelState.AddModelError("ExpectedAmount", ValidationMessages.InvestmentTargetAmountInvalid3); return(View(model)); } model.Status = Common.EditStatus.Updating; var newInvestmentTarget = await _investmentTargetService.AddInvestmentTarget(model); var orderModel = new OrderModel() { Desc = "Dau tu Savenow", MerchantCode = _configuration.GetValue <string>("PaymentParam:merchant_code"), Msisdn = currentUser.PhoneNumber, TransAmount = newInvestmentTarget.OneTimeAmount.ToString("0"), Version = _configuration.GetValue <string>("PaymentParam:version"), IsInvestmentTarget = true }; var order = await _orderService.SaveOrder(orderModel); var check_sum = Helpers.CreateCheckSum(_configuration.GetValue <string>("PaymentSecurity:AccessCode"), _configuration.GetValue <string>("PaymentSecurity:SecretKey"), order.Id.ToString(), _configuration.GetValue <string>("PaymentParam:command"), order.MerchantCode, order.Id.ToString(), order.TransAmount, order.Version); var paymentLink = _configuration.GetValue <bool>("PaymentLink:IsLive") ? _configuration.GetValue <string>("PaymentLink:Live") : _configuration.GetValue <string>("PaymentLink:Test"); var paymentParameters = string.Format("billcode={0}&command={1}&desc={2}&merchant_code={3}&sender_msisdn={4}&order_id={5}&return_url={6}&cancel_url={7}&trans_amount={8}&version={9}&check_sum={10}", order.Id.ToString(), _configuration.GetValue <string>("PaymentParam:command"), orderModel.Desc, _configuration.GetValue <string>("PaymentParam:merchant_code"), currentUser.PhoneNumber, order.Id.ToString(), Url.Action(action: nameof(InvestmentController.DoPayment), controller: "Investment", values: null, protocol: Request.Scheme), Url.Action(action: nameof(InvestmentController.CancelPayment), controller: "Investment", values: null, protocol: Request.Scheme), orderModel.TransAmount, _configuration.GetValue <string>("PaymentParam:version"), check_sum); return(Redirect(paymentLink + paymentParameters)); } } return(View(model)); }