public static void Log(MortgageInfo mortgageInfo, MortgageResult mortgageResult) { SqlConnection connection = Connect(); SqlCommand cmd = new SqlCommand($"INSERT INTO {TableName} VALUES(@principle, @time, @rate, @years, @monthlyPayment)", connection); cmd.Parameters.AddWithValue("principle", mortgageInfo.Principle); cmd.Parameters.AddWithValue("time", DateTime.Now.Ticks); cmd.Parameters.AddWithValue("rate", mortgageInfo.InterestRate); cmd.Parameters.AddWithValue("years", mortgageInfo.DurationYears); cmd.Parameters.AddWithValue("monthlyPayment", mortgageResult.MonthlyPayment); cmd.ExecuteNonQuery(); connection.Close(); }
public ActionResult Index(double Cost, double Principle, double InterestRate, int DurationYears) { MortgageInfo mortgageInfo = new MortgageInfo(Cost, Principle, InterestRate, DurationYears); MortgageResult mortgageResult = new MortgageResult { MonthlyPayment = MortgageLib.MonthlyPayment(mortgageInfo) }; // Saving the results to a database. { MortgageLoggerSQL.TryCreateTables(); // Yes, I am too lazy to run this at the start of the program. Let's just do it here. MortgageLoggerSQL.Log(mortgageInfo, mortgageResult); } return(View("IndexResult", mortgageResult)); }
public static double MonthlyPayment(MortgageInfo m) { return(MonthlyPayment(m.Principle, m.InterestRate, m.DurationYears)); }