예제 #1
0
        public JsonResult Calculate(CarbonCalculationModel postedModel)
        {
            var service     = new CarbonCalculationService();
            var returnModel = service.CalculateCarbon(postedModel);

            return(Json(returnModel));
        }
        public CarbonCalculationReturnModel CalculateCarbon(CarbonCalculationModel calc)
        {
            double carbonKg = new double();
            int    rating   = new int();

            switch (calc.TransportType)
            {
            case JourneyType.Car:
                carbonKg = 0.133 * calc.Distance;   /* Using "medium car" value */
                rating   = 3;
                break;

            case JourneyType.Bus:
                carbonKg = 0.069 * calc.Distance;
                rating   = 5;
                break;

            case JourneyType.Train:
                carbonKg = 0.065 * calc.Distance;   /* Using "underground/metro" value */
                rating   = 6;
                break;

            case JourneyType.Bike:
                carbonKg = 0;
                rating   = 10;
                break;

            case JourneyType.Walk:
                carbonKg = 0;
                rating   = 10;
                break;
            }
            return(new CarbonCalculationReturnModel {
                TransportType = calc.TransportType,
                CarbonKg = carbonKg,
                EcoRating = rating,
            });
        }
예제 #3
0
        //
        // GET: /HelloWorld/

        public string Index(CarbonCalculationModel model)
        {
            return(HtmlEncoder.Default.Encode($"Distance: {model.Distance}, Transport Type: {model.TransportType}"));
        }