Пример #1
0
        public long SaveProblem(EditProblemViewModel model)
        {
            using (var uow = this.factory.GetUnitOfWork())
            {
                var taskRepository = uow.TaskRepository;

                Task task;
                if (model.Id != null)
                {
                    task = taskRepository.Get(model.Id.Value);
                }
                else
                {
                    task = new Task();
                    taskRepository.Add(task);
                }
                task.IsOpened              = model.IsOpened;
                task.MemoryLimitBytes      = model.MemoryLimitBytes;
                task.Name                  = model.Name;
                task.Statement             = model.Statement;
                task.TestsFolder           = model.TestsFolder;
                task.TimeLimitMilliseconds = model.TimeLimitMilliseconds;

                uow.Commit();
                return(task.Id);
            }
        }
Пример #2
0
 public ActionResult EditProblem(EditProblemViewModel model)
 {
     if (ModelState.IsValid)
     {
         var id = _adminService.SaveProblem(model);
         return(RedirectToAction("EditProblem", new { id }));
     }
     return(View(model));
 }
        public ActionResult Edit(int id, EditProblemViewModel viewModel)
        {
            var problem = db.Problems.Find(id);

            if (ModelState.IsValid)
            {
                problem.Description = viewModel.Description;
                problem.Lastname    = viewModel.Lastname;
                problem.Firstname   = viewModel.Firstname;
                problem.Middlename  = viewModel.Middlename;
                problem.Phone       = viewModel.Phone;
                problem.Street      = viewModel.Street;
                problem.Building    = viewModel.Building;
                problem.Flat        = viewModel.Flat;
                problem.Status      = viewModel.Status;
                problem.Comment     = viewModel.Comment;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(viewModel));
        }
        public ActionResult EditProblem(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            problem problem = problmService.GetProblemById(id);

            if (problem == null)
            {
                return(HttpNotFound());
            }
            account user   = accountHelper.getCurrentUser(Session["User"].ToString());
            int     userId = user.id;

            ViewBag.userName  = user.name;
            ViewBag.imagePath = user.imagePath;
            EditProblemViewModel info = new EditProblemViewModel {
                prob = problem, cases = problmService.getTestCasesOfProblem(id)
            };

            return(View(info));
        }
Пример #5
0
        public ActionResult Update(int ProblemID = -1)
        {
            logger.Debug("User " + WebSecurity.GetUserId(User.Identity.Name) +
                         " \"" + User.Identity.Name + "\" visited ProblemsManagement/Problem/Update");

            Problem problem = repository.Problems.FirstOrDefault(p => p.ProblemID == ProblemID);

            if (problem == null)
            {
                logger.Warn("Problem with id = " + ProblemID + " not found");
                throw new HttpException(404, "Problem not found");
            }

            // Read problem info
            string name, description = "Error occurred",
                   inputFormat  = "Error occurred",
                   outputFormat = "Error occurred",
                   checkerCode  = "Error occurred";
            double       timeLimit;
            int          memoryLimit;
            ProblemTypes pt;

            try
            {
                ProblemLegend.Read(LocalPath.AbsoluteProblemsDirectory + problem.ProblemID,
                                   out name,
                                   out timeLimit,
                                   out memoryLimit,
                                   out pt,
                                   out description,
                                   out inputFormat,
                                   out outputFormat);

                string checkerPath = "";
                if (System.IO.File.Exists(LocalPath.AbsoluteProblemsDirectory + problem.ProblemID + "/checker.cpp"))
                {
                    checkerPath = LocalPath.AbsoluteProblemsDirectory + problem.ProblemID + "/checker.cpp";
                }
                else if (System.IO.File.Exists(LocalPath.AbsoluteProblemsDirectory + problem.ProblemID + "/checker.pas"))
                {
                    checkerPath = LocalPath.AbsoluteProblemsDirectory + problem.ProblemID + "/checker.pas";
                }

                using (StreamReader sr = new StreamReader(checkerPath))
                {
                    checkerCode = sr.ReadToEnd();
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error occurred on problem legend reading:", ex);
            }

            EditProblemViewModel viewModel = new EditProblemViewModel()
            {
                ProblemID          = problem.ProblemID,
                Name               = problem.Name,
                ProblemTypesListID = (int)problem.Type,

                TimeLimit   = problem.TimeLimit,
                MemoryLimit = problem.MemoryLimit,

                Description  = description,
                InputFormat  = inputFormat,
                OutputFormat = outputFormat,

                CheckerCode = checkerCode,

                Tournaments = problem.Tournaments.Select(t => t.Name),

                CheckPending = problem.CheckPending
            };

            repository.ProblemTags.Each(t =>
                                        viewModel.ProblemTagsList.Add(new SelectListItem()
            {
                Text     = t.Name,
                Value    = t.ProblemTagID.ToString(),
                Selected = problem.Tags.Count(tag => tag.ProblemTagID == t.ProblemTagID) > 0
            }
                                                                      )
                                        );

            return(View(viewModel));
        }
Пример #6
0
        public ActionResult Update(int ProblemID = -1)
        {
            logger.Debug("User " + WebSecurity.GetUserId(User.Identity.Name) +
                " \"" + User.Identity.Name + "\" visited ProblemsManagement/Problem/Update");

            Problem problem = repository.Problems.FirstOrDefault(p => p.ProblemID == ProblemID);

            if (problem == null)
            {
                logger.Warn("Problem with id = " + ProblemID + " not found");
                throw new HttpException(404, "Problem not found");
            }

            // Read problem info
            string name, description = "Error occurred",
                inputFormat = "Error occurred",
                outputFormat = "Error occurred",
                checkerCode = "Error occurred";
            double timeLimit;
            int memoryLimit;
            ProblemTypes pt;
            try
            {
                ProblemLegend.Read(LocalPath.AbsoluteProblemsDirectory + problem.ProblemID,
                    out name,
                    out timeLimit,
                    out memoryLimit,
                    out pt,
                    out description,
                    out inputFormat,
                    out outputFormat);

                string checkerPath = "";
                if (System.IO.File.Exists(LocalPath.AbsoluteProblemsDirectory + problem.ProblemID + "/checker.cpp"))
                {
                    checkerPath = LocalPath.AbsoluteProblemsDirectory + problem.ProblemID + "/checker.cpp";
                }
                else if (System.IO.File.Exists(LocalPath.AbsoluteProblemsDirectory + problem.ProblemID + "/checker.pas"))
                {
                    checkerPath = LocalPath.AbsoluteProblemsDirectory + problem.ProblemID + "/checker.pas";
                }

                using (StreamReader sr = new StreamReader(checkerPath))
                {
                    checkerCode = sr.ReadToEnd();
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error occurred on problem legend reading:", ex);
            }

            EditProblemViewModel viewModel = new EditProblemViewModel()
            {
                ProblemID = problem.ProblemID,
                Name = problem.Name,
                ProblemTypesListID = (int)problem.Type,

                TimeLimit = problem.TimeLimit,
                MemoryLimit = problem.MemoryLimit,

                Description = description,
                InputFormat = inputFormat,
                OutputFormat = outputFormat,

                CheckerCode = checkerCode,

                Tournaments = problem.Tournaments.Select(t => t.Name),

                CheckPending = problem.CheckPending
            };
            repository.ProblemTags.Each(t =>
                viewModel.ProblemTagsList.Add(new SelectListItem()
                    {
                        Text = t.Name,
                        Value = t.ProblemTagID.ToString(),
                        Selected = problem.Tags.Count(tag => tag.ProblemTagID == t.ProblemTagID) > 0
                    }
                )
            );

            return View(viewModel);
        }