Beispiel #1
0
        public ActionResult Delete()
        {
            string contestIdString = Request.QueryString["id"];

            if (string.IsNullOrEmpty(contestIdString))
            {
                return(new ContentResult());
            }

            int contestId;

            if (!int.TryParse(contestIdString, out contestId))
            {
                return(new ContentResult());
            }

            ContestHandle contest = new ContestHandle(contestId);
            UserHandle    user    = UserSession.GetUserHandle(Session);

            // 检查用户操作权限。
            if (!ContestAuthorization.GetUserAccess(contest, user).HasFlag(DataAccess.Write))
            {
                // 用户对该比赛没有写权限。
                return(new ContentResult());
            }

            ContestManager.Default.RemoveContest(contestId);
            return(new ContentResult());
        }
        public ActionResult ContestDetail()
        {
            string contestIdString = Request.QueryString["id"];

            if (string.IsNullOrEmpty(contestIdString))
            {
                return(QueryResult(1, "Contest ID required."));
            }

            int contestId;

            if (!int.TryParse(contestIdString, out contestId))
            {
                return(QueryResult(2, "Invalid contest ID."));
            }

            // 检查用户权限。
            ContestHandle contest = new ContestHandle(contestId);
            DataAccess    access  = ContestAuthorization.GetUserAccess(contest, UserSession.GetUserHandle(Session));

            if (access == DataAccess.None)
            {
                return(QueryResult(3, "Access denied."));
            }
            else if (access == DataAccess.Read)
            {
                // 用户对于该场比赛处于只读状态。检查比赛的执行状态。
                bool loadProblems = true;
                using (ContestDataProvider contestData = ContestDataProvider.Create(contest, true))
                {
                    if (contestData.Status == ContestStatus.Pending)
                    {
                        loadProblems = false;
                    }
                }

                return(QueryResult(ContestDisplayModel.FromContestHandle(contest, loadProblems)));
            }
            else
            {
                return(QueryResult(ContestDisplayModel.FromContestHandle(contest, true)));
            }
        }
        public ActionResult ContestAccess()
        {
            string contestIdString = Request.QueryString["id"];

            if (string.IsNullOrEmpty(contestIdString))
            {
                return(QueryResult(1, "Contest ID is required."));
            }

            int contestId;

            if (!int.TryParse(contestIdString, out contestId))
            {
                return(QueryResult(2, "Invalid contest ID."));
            }

            ContestHandle contest = new ContestHandle(contestId);
            UserHandle    user    = UserSession.GetUserHandle(Session);

            return(QueryResult(ContestAuthorization.GetUserAccess(contest, user)));
        }
Beispiel #4
0
        public ActionResult SetAnnouncement(FormCollection form)
        {
            string contestIdString = Request.QueryString["id"];

            if (string.IsNullOrEmpty(contestIdString))
            {
                return(new ContentResult());
            }

            int contestId;

            if (!int.TryParse(contestIdString, out contestId))
            {
                return(new ContentResult());
            }

            string announcement = form["announcementContent"];

            if (string.IsNullOrEmpty(announcement))
            {
                return(new ContentResult());
            }

            // 检查用户身份权限。
            ContestHandle contest = new ContestHandle(contestId);
            UserHandle    user    = UserSession.GetUserHandle(Session);

            if (!ContestAuthorization.GetUserAccess(contest, user).HasFlag(DataAccess.Write))
            {
                // 用户对当前的比赛没有写权限。
                return(new ContentResult());
            }

            using (ContestDataProvider contestData = ContestDataProvider.Create(contest, false))
            {
                contestData.Announcement = announcement;
            }

            return(new ContentResult());
        }