public async Task <ActionResult> Run2([FromBody] ProblemSolutionForTransferDto problemSolutionForTransfer)
        {
            CodeExecutionRequest codeExecutionRequest = new CodeExecutionRequest()
            {
                SourceCode = problemSolutionForTransfer.EncodedSourceCode.FromBase64ToString(),
                TestCases  = problemSolutionForTransfer.TestCases.Select(x => new TestCaseRequest()
                {
                    SampleInput    = x.SampleInput,
                    ExpectedOutput = x.ExpectedOutput
                }).ToList()
            };

            var results = await _codeExecutionService.ExecuteAsync(codeExecutionRequest);

            return(Ok(results));
        }
Exemple #2
0
        public async Task <ActionResult> RunSolution([FromBody] SolutionRunRequest solutionToRun)
        {
            // check if student exists
            var student = await _context.Students.FindAsync(solutionToRun.StudentId);

            if (student == null)
            {
                return(NotFound());
            }

            // check if problem exists
            var courseProblem = await _context.CourseProblems
                                .Include(cp => cp.Problem)
                                .ThenInclude(p => p.TestCases)
                                .FirstOrDefaultAsync(p => p.Id == solutionToRun.CourseProblemId);

            if (courseProblem == null)
            {
                return(NotFound());
            }

            // solution doesnt exist, create. else update source code
            var solution = await _context.Solutions.FindAsync(solutionToRun.SolutionId);

            if (solution == null)
            {
                solution = _mapper.Map <Solution> (solutionToRun);
                _context.Solutions.Add(solution);
            }
            else
            {
                solution.SourceCode = solutionToRun.SourceCode;
            }

            await _context.SaveChangesAsync();

            var codeExecutionRequest = new CodeExecutionRequest()
            {
                SolutionId = solution.Id,
                SourceCode = solutionToRun.SourceCode,
                TestCases  = _mapper.Map <List <TestCaseRequest> > (courseProblem.Problem.TestCases)
            };

            var results = await _codeExecutionService.ExecuteAsync(codeExecutionRequest);

            return(Ok(results));
        }