Beispiel #1
0
        public ActionResult Post([FromBody] Game game)
        {
            try
            {
                if (game.NumberOfSimulations <= 0)
                {
                    return(BadRequest("Number of simulations cannot be less or equal to zero"));
                }

                var simulationResult = _simulationService.RunSimulation(game.NumberOfSimulations, game.IsSwitching, game.NumberOfDoors);
                return(Ok(simulationResult));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, $"Something went wrong: {ex.Message}"));
            }
        }
Beispiel #2
0
        public async Task <ActionResult> RunSimulation(SimulationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Strategies = await _strategyService.GetStrategies(CurrentUserId);

                model.Companies = await _companyService.GetCompanies();

                model.CompanyGroups = await _companyService.GetCompanyGroups();

                return(View(model));
            }

            var results = await _simulationService.RunSimulation(await ConvertViewModelToDto(model));

            var resultsModel = await BuildSimulationResultViewModel(model, results);

            return(View("Results", resultsModel));
        }