public TipCalculatorResponse CalculateTip(TipCalculatorRequest data)
        {
            var result = new TipCalculatorResponse();

            result.MealTotal   = data.MealTotal;
            result.TipPercent  = data.TipPercent;
            result.TipAmount   = result.MealTotal * (result.TipPercent / 100);
            result.TotalAmount = result.TipAmount + result.MealTotal;

            return(result);
        }
        public void CalculateTipTest()
        {
            var calculator = new TipCalculator();

            var request = new TipCalculatorRequest {
                MealTotal = 100, TipPercent = 10M
            };

            var result = calculator.CalculateTip(request);

            Assert.AreEqual(result.TipAmount, 10M);
            Assert.AreEqual(result.TotalAmount, 110M);
        }
        public ActionResult TipCalculator(TipCalculatorRequest request)
        {
            if (ModelState.IsValid)
            {
                var calc = new TipCalculator();

                var tipData = new MVCappLabs.Models.Level1.TipCalculationRequest();
                tipData.MealCost   = request.MealCost.Value;
                tipData.TipPercent = request.TipPercent.Value / 100;

                var response = calc.CalculateTip(tipData);

                return(View("TipCalculatorResponse", response));
            }
            return(View("TipCalculator"));
        }
Beispiel #4
0
        public ActionResult TipCalculatorInput(TipCalculatorModel request)
        {
            if (ModelState.IsValid)
            {
                var tipCalc = new TipCalculator();
                var tipData = new TipCalculatorRequest();
                tipData.MealTotal  = request.MealTotal.Value;
                tipData.TipPercent = request.TipPercent.Value;

                var result = tipCalc.CalculateTip(tipData);
                return(View("TipCalculatorOutput", result));
            }
            else
            {
                return(View(request));
            }
        }
        //********Level 1 Labs **********

        public ActionResult TipCalculator()
        {
            var model = new TipCalculatorRequest();

            return(View(model));
        }