Exemple #1
0
        public ActionResult Edit(ContestDetailModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

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

            // 执行用户身份验证。
            ContestHandle handle = new ContestHandle(model.ContestId);

            using (ContestDataProvider data = ContestDataProvider.Create(handle, true))
            {
                if (!UserSession.IsAuthorized(Session) ||
                    string.Compare(data.Creator, UserSession.GetUsername(Session), false) != 0)
                {
                    return(Redirect("~/Error/AccessDenied"));
                }
            }

            model.SaveTo(handle);
            return(Redirect($"~/Contest/Show?id={model.ContestId}"));
        }
Exemple #2
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 #3
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"));
        }
Exemple #4
0
        private bool ValidateContestDetailModel(ContestDetailModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            bool validationPassed = TryValidateModel(model);

            if (!validationPassed)
            {
                ViewBag.TitleErrorMessage                 = ModelStateHelper.GetFirstError(ModelState, "Title");
                ViewBag.CreatorErrorMessage               = ModelStateHelper.GetFirstError(ModelState, "Creator");
                ViewBag.UsergroupNameErrorMessage         = ModelStateHelper.GetFirstError(ModelState, "UsergroupName");
                ViewBag.StartTimeStringErrorMessage       = ModelStateHelper.GetFirstError(ModelState, "StartTimeString");
                ViewBag.EndTimeStringErrorMessage         = ModelStateHelper.GetFirstError(ModelState, "EndTimeString");
                ViewBag.ParticipationModeNameErrorMessage = ModelStateHelper.GetFirstError(ModelState, "ParticipationModeName");
                ViewBag.AuthorizationModeNameErrorMessage = ModelStateHelper.GetFirstError(ModelState, "AuthorizationModeName");
            }

            if (string.Compare(model.AuthorizationModeName, "Protected", true) == 0 &&
                (string.IsNullOrEmpty(model.Password) || model.Password.Length < 6))
            {
                validationPassed             = false;
                ViewBag.PasswordErrorMessage = "Password should be at least 6 characters long.";
            }

            DateTime startTime = DateTime.Parse(model.StartTimeString);
            DateTime endTime   = DateTime.Parse(model.EndTimeString);

            if (endTime <= startTime)
            {
                validationPassed = false;
                ViewBag.EndTimeStringErrorMessage = "End time must be later than start time.";
            }

            return(validationPassed);
        }
Exemple #5
0
        public ActionResult Edit()
        {
            // 检查查询参数。
            if (string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                return(Redirect("~/Contest"));
            }

            int contestId;

            if (!int.TryParse(Request.QueryString["id"], out contestId))
            {
                return(Redirect("~/Contest"));
            }

            if (!ContestManager.Default.IsContestExist(contestId))
            {
                return(Redirect("~/Contest"));
            }

            ContestHandle contest = new ContestHandle(contestId);

            using (ContestDataProvider data = ContestDataProvider.Create(contest, false))
            {
                // 验证用户身份权限。
                if (!UserSession.IsAuthorized(Session) ||
                    string.Compare(data.Creator, UserSession.GetUsername(Session), false) != 0)
                {
                    return(Redirect("~/Error/AccessDenied"));
                }
            }

            ContestDetailModel model = ContestDetailModel.FromContestHandle(contest);

            return(View(model));
        }