コード例 #1
0
        public IActionResult ProblemContestOverview(Guid id, Guid contest)
        {
            var problem        = _problemRepository.GetItem(id);
            var currentContest = _contestRepository.GetItem(contest);
            var user           = User?.Identity?.Name;
            int score          = 0;


            //see the score for this problem in contest for the user that is logged in
            if (user != null)
            {
                //list with submission
                var contestSubmissionList      = _submisionContestRepository.GetListOfSubmisionForSpecificContest(contest).ToList();
                var lstOfSubmissionForAProblem = contestSubmissionList.Where(x => x.Submision.ProblemId == id &&
                                                                             x.Submision.UserName == user).
                                                 OrderByDescending(x => x.Submision.Score).ToList();
                score = lstOfSubmissionForAProblem.FirstOrDefault() == null ? 0 : lstOfSubmissionForAProblem.First().Submision.Score;
            }


            var problemContestViewModel = new ProblemContestDetailsViewModel
            {
                ContestId       = contest,
                Problem         = problem,
                SelectListItems = _compilers,
                Score           = score,
                StartDate       = currentContest.StartDate,
                EndDate         = currentContest.EndDate
            };

            return(View(problemContestViewModel));
        }
コード例 #2
0
        public IActionResult Edit(Guid id)
        {
            var problem = _problemRepository.GetItem(id);

            if (problem == null)
            {
                return(RedirectToAction("Index"));
            }
            return(View(problem));
        }
コード例 #3
0
        public IActionResult ProblemSolution(Guid id)
        {
            var solution = _solutionRepository.GetSolutionByProblem(id);
            var problem  = _problemRepository.GetItem(id);

            var solModel = new SolutionViewModel
            {
                ProblemId   = id,
                ProblemName = problem.ProblemName,
                Solution    = solution
            };

            return(View(solModel));
        }
コード例 #4
0
        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());
        }