Esempio n. 1
0
        public async Task <IActionResult> ValidateSolutionAsync(Solution model, int taskId)
        {
            Solution solution = new Solution();

            // In case user edits value from browser || .Any()
            solution.selectedTask = _context.AlgorithmTask.Find(taskId);

            using (var solutionRepository = new SolutionRepository(_context))
            {
                if (ModelState.IsValid && solution.selectedTask != null)
                {
                    solution = await solutionRepository.solveAlgorithm(model.code, taskId, model.nickName);
                }
                else
                {
                    solution.code           = model.code;
                    solution.nickName       = model.nickName;
                    solution.algorithmTasks = await _context.AlgorithmTask.ToListAsync();
                }
            }

            return(View(nameof(Index), solution));
        }