static void Main(string[] args) { var isContinue = true; while (isContinue) //Loop while user not enter 'Exit' { ILoanCalculationModel loanInfo = null; var loanmanager = new LoanManager(); var loanModel = InputHelper.FillLoanFields(); // Filling viewModel from console try { loanInfo = loanmanager.CalculateLoanStatistics(loanModel); //Calculating loan info } //Catching Bl exceptions and writin to log catch (InvalidAmountException) { Log.Error(Errors.InvalidAmount); } catch (InvalidInterestException) { Log.Error(Errors.InvalidInterest); } catch (InvalidDownPaymentException) { Log.Error(Errors.InvalidDownPayment); } catch (InvalidTermException) { Log.Error(Errors.InvalidTerm); } catch (LoanInfoModelNotFoundException) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(Errors.LoanInfoModelNotFound); Console.ResetColor(); Log.Error(Errors.LoanInfoModelNotFound); } catch (InvalidTotalInterestException) { Log.Error(Errors.InvalidTotalInterest); } catch (InvalidMonthlyPaymentException) { Log.Error(Errors.InvalidMonthlyPayment); } catch (InvalidTotalPaymentException) { Log.Error(Errors.InvalidTotalPayment); } InputHelper.WriteLoanInfo(loanInfo); // Writing to the display Console.WriteLine(Errors.ExitMessage); var exit = Console.ReadLine(); if (!string.IsNullOrEmpty(exit)) // Trying to exit { isContinue = exit.ToLower() != "e"; } } }
public static void WriteLoanInfo(ILoanCalculationModel infoModel) // Write json to console { JObject jObject; if (infoModel != null) { jObject = new JObject(new JProperty(LoanRes.MonthlyPayment, Math.Round(infoModel.MonthlyPayment, 2)), new JProperty(LoanRes.TotalInterest, Math.Round(infoModel.TotalInterest, 2)), new JProperty(LoanRes.TotalPayment, Math.Round(infoModel.TotalPayment, 2))); } else { jObject = new JObject(); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(jObject); Console.ResetColor(); Console.WriteLine(); }