public async Task <IActionResult> ImportFileExecute([FromForm] FileExecutionViewModel file) { var reader = new StreamReader(file.File.OpenReadStream()); string line; while ((line = reader.ReadLine()) != null) { var userToBeRegistered = line.Split(';'); if (userToBeRegistered.Length < 7) { continue; } var userToRegister = new UserInformationViewModel { Nume = userToBeRegistered[0], Prenume = userToBeRegistered[1], Profesor = userToBeRegistered[2], Clasa = userToBeRegistered[3], Scoala = userToBeRegistered[4], Username = userToBeRegistered[5], Password = userToBeRegistered[6] }; var result = await _userInformationService.RegisterUser(userToRegister, string.Empty); if (result == false) { //log the errors ModelState.AddModelError("", $"Something bad happened for user + {userToRegister.Nume}"); } } return(RedirectToAction(nameof(Index), new { searchString = string.Empty })); }
public async Task <IActionResult> ProblemExecute([FromForm] FileExecutionViewModel 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 }; //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 _submisionRepository.AddAsync(submission); await Task.Run(() => VerificaThread(submissionDtoModel)); return(RedirectToAction("GetProblem", new { id = Guid.Parse(model.ProblemId) })); }