public IActionResult Form(MVSimulationViewModel formViewModel)
        {
            if (ModelState.IsValid)
            {
                // Store current form data in the cache
                _cache.Set <MVSimulationViewModel>("MV_ViewModel", formViewModel);

                // Store the person in the cache
                var person = BuildPerson(formViewModel);
                _cache.Set <MotorVehiclePerson>("MV_PERSON", person);

                // Run the simulation
                var simulationRequest = BuildRequest(formViewModel);
                var id = _requestHandler.Handle(simulationRequest);
                return(RedirectToAction("Results", new { id }));
            }
            return(View("Form", formViewModel));
        }
        private MotorVehiclePerson BuildPerson(MVSimulationViewModel vm)
        {
            var weeklySchedule = new MvoSchedule()
            {
                Hours = new List <HourSet>()
            };

            foreach (var vmHour in vm.Person.Hours)
            {
                weeklySchedule.Hours.Add(new HourSet(vmHour.HoursCmvo.Value, vmHour.HoursHmvo.Value, vmHour.HoursOther.Value, vmHour.IsHoliday));
            }

            var result = new MotorVehiclePerson()
            {
                Id             = Guid.NewGuid(),
                WeeklySchedule = weeklySchedule
            };

            return(result);
        }
 private SimulationRequest <MotorVehicleSimulationCaseRequest> BuildRequest(MVSimulationViewModel vm)
 {
     return(new SimulationRequest <MotorVehicleSimulationCaseRequest>()
     {
         BaseCaseRequest = new MotorVehicleSimulationCaseRequest()
         {
             StandardCmvoDaily = vm.BaseCase.StandardCmvoDaily,
             StandardCmvoWeekly = vm.BaseCase.StandardCmvoWeekly,
             StandardOtherDaily = vm.BaseCase.StandardOtherDaily,
             StandardOtherWeekly = vm.BaseCase.StandardOtherWeekly,
             StandardHighwayWeekly = vm.BaseCase.StandardHighwayWeekly,
             StandardHighwayReduction = vm.BaseCase.StandardHighwayReduction,
         },
         VariantCaseRequest = new MotorVehicleSimulationCaseRequest()
         {
             StandardCmvoDaily = vm.VariantCase.StandardCmvoDaily,
             StandardCmvoWeekly = vm.VariantCase.StandardCmvoWeekly,
             StandardOtherDaily = vm.VariantCase.StandardOtherDaily,
             StandardOtherWeekly = vm.VariantCase.StandardOtherWeekly,
             StandardHighwayWeekly = vm.VariantCase.StandardHighwayWeekly,
             StandardHighwayReduction = vm.VariantCase.StandardHighwayReduction,
         },
     });
 }
        public IActionResult Form()
        {
            var vm = new MVSimulationViewModel();

            return(View(vm));
        }