예제 #1
0
 /// <summary>
 /// Calculate loan action.
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public ActionResult CalculateLoan(LoanContextModel model)
 {
     if (ModelState.IsValid)
     {
         LoanCalculator calculator = new LoanCalculator(model.ToLoanContext());
         LoanCalculationOutput output = calculator.Calculate();
         return (View(new LoanCalculationResultsModel(model, output)));
     }
     else
     {
         return (View("Index", model));
     }
 }
예제 #2
0
파일: Program.cs 프로젝트: retroburst/Kata
        /// <summary>
        /// Entry point for program.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public static void Main(string[] args)
        {
            LoanContext context = null;
            LoanCalculator calculator = null;
            LoanCalculationOutput output = null;
            LoanCalculationOutputStreamWriter writer = null;
            try
            {
                // clean the program name
                programName = programName.Replace(".exe",  string.Empty);
                // check we have the required number of arguments
                if(args.Length != EXPECTED_ARGUMENT_COUNT)
                {
                    PrintUsage();
                    return;
                }
                string outputFilename = BuildOutputFilename();
                context = new LoanContext();
                ProcessArguments(args, context);
                context.TodaysDate = DateTime.Now;
                calculator = new LoanCalculator(context);
                output = calculator.Calculate();
                writer = new LoanCalculationOutputStreamWriter(context, output);

                using(StreamWriter fs = new StreamWriter(new FileStream(outputFilename, FileMode.Create)))
                {
                    writer.WriteOutputHeader(fs, programName);
                    writer.WritetCalculations(fs);
                }

                writer.WriteOutputHeader(System.Console.Out, programName);
                writer.WritetCalculations(System.Console.Out);
                System.Console.WriteLine(string.Format("Ouput written to file '{0}'.", outputFilename));
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(string.Format("Exception occurred: {0}", ex.Message));
                System.Console.WriteLine(string.Format("\n\n{0}", ex.StackTrace));
            }
        }