public InvestmentResult CalculateROI([FromBody] CalculateROIRequest request) { var investmentResult = _investmentService.CalculateResult(request.InvestmentDetails); var exchangedResult = new InvestmentResult { InvestmentReturn = _exchangeRateService.Exchange("AUD", "USD", investmentResult.InvestmentReturn), Fees = _exchangeRateService.Exchange("AUD", "USD", investmentResult.Fees) }; return(exchangedResult); }
public async Task <IActionResult> CalculateROIAndFee(CalculateROIRequest requestModel) { //map request to list of dtos var dtos = _investmentOptionMapper.FromCalculateROIRequestToInvestmentOptionDtos(requestModel); //calculate result CalculationModel calculationModel = _investmentOptionService.CalculateTotalROIAndFee(requestModel.TotalAmount, dtos); //get exchange rate from 3rd-party api double rate = await _currencyConversionService.GetAUDToUSDRate(); //get final result _investmentOptionService.CovertTotalROIAndFee(calculationModel, rate); //map to response var investmentOptionCalculationResponse = _investmentOptionMapper.FromCalculationModelToInvestmentOptionCalculationResponse(calculationModel, "USD"); return(Ok(investmentOptionCalculationResponse)); }
public List <InvestmentOptionDto> FromCalculateROIRequestToInvestmentOptionDtos(CalculateROIRequest requestModel) { List <InvestmentOptionDto> investmentOptionDtos = new List <InvestmentOptionDto>(); foreach (var option in requestModel.Options) { InvestmentOptionDto investmentOptionDto = new InvestmentOptionDto { InvestmentOption = option.InvestmentOption, InvestmentPercentage = option.InvestmentPercentage, InvestmentAmount = _investmentOptionService.CalculateInvestmentAmount(requestModel.TotalAmount, option.InvestmentPercentage) }; investmentOptionDtos.Add(investmentOptionDto); } return(investmentOptionDtos); }