Example #1
0
        public async Task <IActionResult> Plan(InvestmentBasisDTO investmentBasis)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            return(Ok(await _planService.CalculateInvestmentPotential(investmentBasis).ConfigureAwait(false)));
        }
        public async Task <InvestmentResultDTO> CalculateInvestmentPotential(InvestmentBasisDTO basis)
        {
            var result = AutoMapper.Mapper.Map <InvestmentResultDTO>(basis);

            for (int i = 1; i <= result.Years; i++)
            {
                var record = new InvestmentRecordDTO {
                    Year = i, Contribution = basis.AnnualContributions
                };

                record.Contribution += record.Contribution * (result.AnnualContributionROC / 100) * (i - 1);
                record.Interest      = (result.Total + record.Contribution) * (result.APR / 100);
                record.Total         = result.Total + record.Contribution + record.Interest;

                result.Records.Add(record);
            }

            var basisEntity = AutoMapper.Mapper.Map <Models.Entities.InvestmentBasisEntity>(basis);
            await _investmentRepository.SaveBasisAsync(basisEntity).ConfigureAwait(false);

            return(result);
        }