// GET: Archieve/Environment?id={ProblemID}
        public ActionResult Environment()
        {
            // 检查用户权限。
            if (!UserSession.IsAuthorized(Session) ||
                !UserAuthorization.CheckAccessRights(UserGroup.Administrators, UserSession.GetUserGroup(Session)))
            {
                return(Redirect("~/Error/AccessDenied"));
            }

            if (string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                return(Redirect("~/Archieve"));
            }

            ProblemHandle handle = ProblemArchieveManager.Default.GetProblemById(Request.QueryString["id"]);

            if (handle == null)
            {
                return(Redirect("~/Error/ProblemNotExist"));
            }

            ProblemEnvironmentModel model = ProblemEnvironmentModel.FromProblemHandle(handle);

            return(View(model));
        }
        // GET: Archieve/Modify
        public ActionResult Modify()
        {
            if (!UserAuthorization.CheckAccessRights(UserGroup.Administrators, UserSession.GetUserGroup(Session)))
            {
                return(Redirect("~/Error/AcceesDenied"));
            }
            if (string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                // 缺少题目 ID。
                return(Redirect("~/Error/ProblemNotExist"));
            }
            ;

            // 查询题目信息。
            ProblemHandle handle = ProblemArchieveManager.Default.GetProblemById(Request.QueryString["id"]);

            if (handle == null)
            {
                // 题目不存在于数据库中。
                return(Redirect("~/Error/ProblemNotExist"));
            }

            ProblemDetailModel model = ProblemDetailModel.FromProblemHandle(handle);

            return(View(model));
        }
        // GET: Archieve/Add
        public ActionResult Add()
        {
            if (!UserAuthorization.CheckAccessRights(UserGroup.Administrators, UserSession.GetUserGroup(Session)))
            {
                // 用户权限不足。
                return(Redirect("~/Error/AccessDenied"));
            }

            return(View(new ProblemDetailModel()));
        }
        public ActionResult Delete()
        {
            if (!UserAuthorization.CheckAccessRights(UserGroup.Administrators, UserSession.GetUserGroup(Session)))
            {
                return(new ContentResult());
            }
            if (Request.QueryString["id"] == null)
            {
                return(new ContentResult());
            }

            ProblemArchieveManager.Default.RemoveProblem(Request.QueryString["id"]);
            return(new ContentResult());
        }
        // GET: Archieve/TestSet?id={ProblemID}
        public ActionResult TestSet()
        {
            // 执行用户身份验证。
            if (!UserSession.IsAuthorized(Session))
            {
                return(Redirect("~/Error/AccessDenied"));
            }

            // 检查查询参数。
            if (string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                return(Redirect("~/Archieve"));
            }

            string        problemId     = Request.QueryString["id"];
            ProblemHandle problemHandle = ProblemArchieveManager.Default.GetProblemById(problemId);

            if (problemHandle == null)
            {
                // 给定的题目不存在。
                return(Redirect("~/Archieve"));
            }

            using (ProblemDataProvider problemData = ProblemDataProvider.Create(problemHandle, true))
            {
                // 执行进一步身份验证。
                if (problemData.ContestId == -1)
                {
                    if (!UserAuthorization.CheckAccessRights(UserGroup.Administrators, UserSession.GetUserGroup(Session)))
                    {
                        return(Redirect("~/Error/AccessDenied"));
                    }
                }
                else
                {
                    ContestHandle contestHandle = new ContestHandle(problemData.ContestId);
                    using (ContestDataProvider contestData = ContestDataProvider.Create(contestHandle, true))
                    {
                        if (string.Compare(contestData.Creator, UserSession.GetUsername(Session), false) != 0)
                        {
                            return(Redirect("~/Error/AccessDenied"));
                        }
                    }
                }
            }

            // TODO: 完成 Archieve/TestSet 控制器逻辑。
            return(View());
        }
        public ActionResult ChangeUsergroup(FormCollection form)
        {
            // 检查查询参数。
            if (string.IsNullOrEmpty(Request.QueryString["username"]) ||
                string.IsNullOrEmpty(form["usergroup"]))
            {
                return(Redirect("~/Profile"));
            }

            string     username = Request.QueryString["username"];
            UserHandle handle   = UserManager.Default.QueryUserByName(username);

            if (handle == null)
            {
                // 指定的用户不存在。
                return(Redirect("~/Profile"));
            }

            // 检查用户操作权限。
            if (!UserSession.IsAuthorized(Session) ||
                !UserAuthorization.CheckAccessRights(UserGroup.Administrators, UserSession.GetUserGroup(Session)) ||
                string.Compare(username, UserSession.GetUsername(Session), false) == 0)
            {
                return(Redirect("~/Error/AccessDenied"));
            }

            UserGroup targetGroup;

            try
            {
                targetGroup = UsergroupConvert.ConvertFromString(form["usergroup"]);
            }
            catch (ArgumentException)
            {
                return(Redirect("~/Profile"));
            }

            // 执行操作。
            using (UserDataProvider data = UserDataProvider.Create(handle, false))
            {
                data.UserGroup = targetGroup;
            }

            return(Content(string.Empty));
        }
        public ActionResult Add(ProblemDetailModel model)
        {
            if (!UserAuthorization.CheckAccessRights(UserGroup.Administrators, UserSession.GetUserGroup(Session)))
            {
                // 用户权限不足。
                return(Redirect("~/Error/AccessDenied"));
            }

            // 检查数据模型验证状态。
            bool hasError = false;

            TryValidateModel(model);
            if (ModelState.ContainsKey("Id") && ModelState["Id"].Errors.Count > 0)
            {
                hasError = true;
                ViewBag.ProblemIdErrorMessage = ModelState["Id"].Errors[0].ErrorMessage;
            }
            if (ModelState.ContainsKey("Title") && ModelState["Title"].Errors.Count > 0)
            {
                hasError = true;
                ViewBag.TitleErrorMessage = ModelState["Title"].Errors[0].ErrorMessage;
            }

            if (hasError)
            {
                return(View(model));
            }

            string problemId = "BIT" + model.ProblemId;

            if (ProblemArchieveManager.Default.IsProblemExist(problemId))
            {
                ViewBag.ProblemIdErrorMessage = "Problem with the same ID already exist in the archieve.";
                return(View(model));
            }

            // 在题目库中创建新题目。
            ProblemHandle handle = ProblemArchieveManager.Default.CreateProblem(problemId);

            model.SaveTo(handle);

            return(Redirect("~/Archieve"));
        }
        public ActionResult Environment(ProblemEnvironmentModel model)
        {
            // 检查操作权限。
            if (!UserSession.IsAuthorized(Session) ||
                !UserAuthorization.CheckAccessRights(UserGroup.Administrators, UserSession.GetUserGroup(Session)))
            {
                return(Redirect("~/Error/AccessDenied"));
            }

            if (!TryValidateModel(model))
            {
                if (ModelState["TimeLimit"] != null && ModelState["TimeLimit"].Errors.Count > 0)
                {
                    ViewBag.TimeLimitErrorMessage = ModelState["TimeLimit"].Errors[0].ErrorMessage;
                }
                if (ModelState["MemoryLimit"] != null && ModelState["MemoryLimit"].Errors.Count > 0)
                {
                    ViewBag.MemoryLimitErrorMessage = ModelState["MemoryLimit"].Errors[0].ErrorMessage;
                }
                return(View(model));
            }
            if (string.IsNullOrEmpty(Request.Form["ProblemId"]))
            {
                return(Redirect("~/Archieve"));
            }

            // 更新数据库数据。
            ProblemHandle handle = ProblemArchieveManager.Default.GetProblemById(model.ProblemId);

            if (handle == null)
            {
                return(Redirect("~/Error/ProblemNotExist"));
            }

            using (ProblemDataProvider data = ProblemDataProvider.Create(handle, false))
            {
                data.TimeLimit      = model.TimeLimit;
                data.MemoryLimit    = model.MemoryLimit;
                data.IsSpecialJudge = model.UseSpecialJudge;
            }

            return(Redirect(string.Format("~/Archieve/ShowProblem?id={0}", model.ProblemId)));
        }
Exemple #9
0
        public ActionResult Add()
        {
            // 执行用户身份验证。
            if (!UserSession.IsAuthorized(Session) ||
                !UserAuthorization.CheckAccessRights(UserGroup.Insiders, UserSession.GetUserGroup(Session)))
            {
                return(Redirect("~/Error/AccessDenied"));
            }

            ContestDetailModel model = new ContestDetailModel()
            {
                Creator = UserSession.GetUsername(Session)
            };

            DateTime defaultStartTime = DateTime.Now.AddMinutes(15D);

            model.StartTimeString = defaultStartTime.ToString("yyyy-MM-dd HH:mm:ss");
            model.EndTimeString   = defaultStartTime.AddHours(2D).ToString("yyyy-MM-dd HH:mm:ss");

            return(View(model));
        }
Exemple #10
0
        public ActionResult Add(ContestDetailModel model)
        {
            // 执行用户身份验证。
            if (!UserSession.IsAuthorized(Session) || !UserAuthorization.CheckAccessRights(UserGroup.Insiders,
                                                                                           UserSession.GetUserGroup(Session)))
            {
                return(Redirect("~/Error/AccessDenied"));
            }

            // 验证数据模型。
            if (!ValidateContestDetailModel(model))
            {
                return(View(model));
            }

            // 创建比赛。
            ContestHandle handle = ContestManager.Default.CreateContest();

            model.SaveTo(handle);

            return(Redirect("~/Contest"));
        }
        public ActionResult Modify(ProblemDetailModel model)
        {
            if (!UserAuthorization.CheckAccessRights(UserGroup.Administrators, UserSession.GetUserGroup(Session)))
            {
                return(Redirect("~/Error/AccessDenied"));
            }

            // 验证模型。
            bool hasError = false;

            TryValidateModel(model);
            if (ModelState["Title"] != null && ModelState["Title"].Errors.Count > 0)
            {
                hasError = true;
                ViewBag.TitleErrorMessage = ModelState["Title"].Errors[0].ErrorMessage;
            }

            if (hasError)
            {
                return(View(model));
            }

            // 查询题目实体。
            ProblemHandle handle = ProblemArchieveManager.Default.GetProblemById(model.ProblemId);

            if (handle == null)
            {
                return(Redirect("~/Error/ProblemNotExist"));
            }

            // 写入修改后的数据。
            model.ResetNullStrings();
            model.SaveTo(handle);

            return(Redirect("~/Archieve"));
        }