/// <summary>
        ///  Get Result
        /// </summary>
        /// <param name="argumentModel"></param>
        /// <param name="fetchMarketData"></param>
        /// <returns></returns>
        public MarketRateOutputModel GetQuote(ArgumentModel argumentModel, List <MarketData> fetchMarketData)
        {
            // validate loand amount
            ValidateRequestedAmount(argumentModel.RequestedAmount, fetchMarketData);

            // find possible quote
            var possibleQuotes = FindPossibleQuotes(argumentModel.RequestedAmount, fetchMarketData);

            // check present quotes
            if (possibleQuotes.Count == 0)
            {
                throw new Exception(ErrorMessage.ThereIsNoAvailableOffer);
            }

            // assing default values
            var result = new MarketRateOutputModel
            {
                Rate           = 0,
                MonthlyPayment = 0,
                RequstedAmount = argumentModel.RequestedAmount,
                TotalPayment   = 0
            };

            // combine selected quote
            foreach (var possibleQuote in possibleQuotes)
            {
                result.Rate += (double)(possibleQuote.RequstedAmount * (decimal)possibleQuote.Rate) /
                               (double)result.RequstedAmount;
                result.MonthlyPayment += possibleQuote.MonthlyPayment;
                result.TotalPayment   += possibleQuote.TotalPayment;
            }

            return(result);
        }
예제 #2
0
 /// <summary>
 ///     Print Result
 /// </summary>
 /// <param name="result"></param>
 private static void PrintResult(MarketRateOutputModel result)
 {
     Console.WriteLine($"Requested amount: £{result.RequstedAmount:0.##}");
     Console.WriteLine($"Rate: {result.Rate:P1}");
     Console.WriteLine($"Monthly repayment: £{result.MonthlyPayment:0.00}");
     Console.WriteLine($"Total repayment: £{result.TotalPayment:0.00}");
 }