public async Task <IActionResult> Goal(InvestmentGoalDTO goal) { if (!ModelState.IsValid) { return(BadRequest()); } return(Ok(await _planService.CalculateForInvestmentGoal(goal).ConfigureAwait(false))); }
public async Task <IEnumerable <InvestmentGoalResultDTO> > CalculateForInvestmentGoal(InvestmentGoalDTO goal) { var result = new List <InvestmentGoalResultDTO>(); for (int i = 1; i <= 5; i++) { for (double j = 1; j <= 10; j++) { var investmentGoal = new InvestmentGoalResultDTO { APR = j, YearsInvested = i * 10 }; var mpr = j / 100d / 12d; var months = investmentGoal.YearsInvested * 12; var total = goal.MonthlyWithdrawAmount / mpr * 1.2; investmentGoal.TotalExpectedInvestment = total; investmentGoal.MonthlyInvestmentRequired = (total - goal.InitialInvestment) / months; result.Add(investmentGoal); } } var goalEntity = AutoMapper.Mapper.Map <Models.Entities.InvestmentGoalEntity>(goal); await _investmentRepository.SaveGoalsAsync(goalEntity).ConfigureAwait(false); return(result); }