public async Task <IActionResult> ProblemContestExecute([FromForm] FileExecutionContestViewModel model) { //read the content of the file Tuple <string, long> fileContent = await FileHelpers.ProcessFormFile(model.File, ModelState); double sizeOfFile = (fileContent.Item2) % 1000; var compilationModel = new CompilationModel { Content = fileContent.Item1, Language = model.Compilator, ProblemName = model.ProblemName, Username = User.Identity.Name }; //save the submission var submission = new Submision { SubmisionId = Guid.NewGuid(), DataOfSubmision = DateTime.Now, Compilator = model.Compilator, ProblemId = Guid.Parse(model.ProblemId), SourceSize = sizeOfFile.ToString(), StateOfSubmision = SubmissionStatus.NotCompiled.ToString(), UserName = User.Identity.Name, MessageOfSubmision = string.Empty, Score = 0, JobQueued = false, SourceCode = fileContent.Item1 }; await _submisionRepository.AddAsync(submission); var submissionContest = new SubmisionContest { SubmisionContestId = Guid.NewGuid(), ContestId = model.ContestId, SubmisionId = submission.SubmisionId }; await _submisionContestRepository.AddAsync(submissionContest); //build the submission dto var problem = _problemRepository.GetItem(submission.ProblemId); string problemName = problem.ProblemName; int nrOfTests = _testRepository.GetNumberOfTestForProblem(problem.ProblemId); var submissionDtoModel = new SubmisionDto { Compilator = submission.Compilator, ProblemName = problemName, Content = submission.SourceCode, SubmissionId = submission.SubmisionId, UserName = User.Identity.Name, MemoryLimit = problem.MemoryLimit, TimeLimit = problem.TimeLimit, NumberOfTests = nrOfTests, FileName = problemName.ToLower() }; await Task.Run(() => VerificaThread(submissionDtoModel)); return(RedirectToAction(nameof(ProblemsOverview), new { id = model.ContestId })); }
[HttpPost] //it will be api public async Task CreateSubmision([FromBody] Submision submision) { await _submisionRepository.AddAsync(submision); }