public async Task <IActionResult> Add([FromForm] TestsViewModel test) { if (ModelState.IsValid) { string testInputContent = string.Empty; string testOutputContent = string.Empty; Tuple <string, long> fileContentInput = await FileHelpers.ProcessFormFile(test.FileInput, ModelState); Tuple <string, long> fileContentOutput = await FileHelpers.ProcessFormFile(test.FileOutput, ModelState); testInputContent = fileContentInput.Item1; testOutputContent = fileContentOutput.Item1; var newTest = new Tests { TestNumber = test.TestNumber, Scor = test.Scor, FisierIn = test.FisierIn, FisierOk = test.FisierOk, TestId = Guid.NewGuid(), ProblemId = test.ProblemId, TestInput = testInputContent, TestOutput = testOutputContent }; //save to server the test. var problem = _problemRepository.GetItem(newTest.ProblemId); //first we save the .in file the the ok file TestsModel testsInputModel = new TestsModel { Content = newTest.TestInput, FileName = newTest.FisierIn, ProblemName = problem.ProblemName }; var inputFileGenerated = await GenerateInputFile(testsInputModel); if (inputFileGenerated == true) { //generate for the .ok file var testOkModel = new TestsModel { Content = newTest.TestOutput, FileName = newTest.FisierOk, ProblemName = problem.ProblemName }; var outputFileGenerated = await GenerateInputFile(testOkModel); if (outputFileGenerated == true) { //ok, we can save in the database _testRepository.Create(newTest); _testRepository.Save(); return(RedirectToAction(nameof(Index), new { id = test.ProblemId })); } else { return(View()); } } else { return(View()); } } return(View()); }
public int Create(Test test) { return(_testsRepository.Create(test)); }