Esempio n. 1
0
        public ActionResult AddSolution(AddSolutionViewModel Model)
        {
            if (ModelState.IsValid)
            {
                if (Model.SolutionFile.ContentLength > 262144)
                {
                    TempData["ErrorMessage"] = "Максимальный размер файла - 256 кб";
                    return RedirectToAction("Problem",
                        new {
                            tournamentID = Model.TournamentID,
                            problemID = Model.ProblemID
                        });
                }

                Tournament tournament = repository.Tournaments.FirstOrDefault(t => t.TournamentID == Model.TournamentID);
                Problem problem = repository.Problems.FirstOrDefault(p => p.ProblemID == Model.ProblemID);

                if (tournament != null && problem != null &&
                    (Roles.IsUserInRole("Judge") || Roles.IsUserInRole("Administrator") ||
                    (tournament.EndDate >= DateTime.Now && tournament.StartDate <= DateTime.Now)))
                {
                    for (int i = 0; i < 1; i++)
                    {
                        int userID = WebSecurity.GetUserId(User.Identity.Name);
                        Solution solution = new Solution
                            {
                                UserID = userID,
                                TournamentID = Model.TournamentID,
                                ProblemID = Model.ProblemID,
                                FileName = Path.GetFileName(Model.SolutionFile.FileName),
                                DataType = Model.SolutionFile.ContentType,
                                ProgrammingLanguage = (ProgrammingLanguages)Model.ProgrammingLanguageID,
                                SendTime = DateTime.Now,
                                Result = TestResults.Waiting
                            };

                        repository.SaveSolution(solution);

                        string relativePath = Path.Combine(
                            LocalPath.RelativeSolutionsDirectory,
                            userID.ToString(),
                            solution.ProblemID.ToString());
                        string absolutePath = Path.Combine(
                            LocalPath.AbsoluteSolutionsDirectory,
                            userID.ToString(),
                            solution.ProblemID.ToString());

                        if (!Directory.Exists(absolutePath))
                            Directory.CreateDirectory(absolutePath);

                        string fileName = solution.SolutionID.ToString();
                        absolutePath = Path.Combine(absolutePath, fileName);
                        relativePath = Path.Combine(relativePath, fileName);
                        Model.SolutionFile.SaveAs(absolutePath);

                        solution.Path = relativePath;
                        if (problem.CheckPending == true)
                        {
                            solution.Result = TestResults.CHKP;
                        }
                        repository.SaveSolution(solution);

                        if (problem.CheckPending == false)
                        {
                            TestersSingleton.Instance.AddSolutionForChecking(
                                Model.ProblemID, solution.SolutionID, solution.ProgrammingLanguage,
                                tournament.Format, problem.Type, relativePath, solution.FileName);
                        }

                        logger.Info("User " + WebSecurity.GetUserId(User.Identity.Name) +
                            " \"" + User.Identity.Name + "\" add solution: PL = " + solution.ProgrammingLanguage +
                            ", TournamentID = " + Model.TournamentID +
                            ", ProblemID = " + Model.ProblemID + ", SolutionID = " + solution.SolutionID);
                    }
                }
            }
            return RedirectToAction("Problem",
                new
                {
                    tournamentID = Model.TournamentID,
                    problemID = Model.ProblemID
                });
        }
Esempio n. 2
0
        /// <summary>
        /// Partial view for solutions adding.
        /// </summary>
        /// <returns>ProblemsListViewModel</returns>
        public PartialViewResult AddSolution(int TournamentID, int ProblemID)
        {
            Problem problem = repository.Problems.FirstOrDefault(p => p.ProblemID == ProblemID);

            AddSolutionViewModel viewModel = new AddSolutionViewModel()
                {
                    PT = problem.Type,
                    ProblemID = ProblemID,
                    TournamentID = TournamentID,
                    ProgrammingLanguageID = problem.Type == ProblemTypes.Open ? (int)ProgrammingLanguages.Open : 0
                };

            return PartialView(viewModel);
        }