protected override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); Int32 cid = filterContext.RouteData.GetInt32("cid", -1); if (cid <= 0) { throw new InvalidRequstException(RequestType.Contest); } ContestEntity contest = ContestManager.GetContest(cid); Boolean hasPermission = AdminManager.HasPermission(PermissionType.ContestManage); if (!hasPermission && contest.IsHide) { throw new NoPermissionException("You have no privilege to view this contest!"); } if (!hasPermission && contest.StartTime > DateTime.Now) { throw new NoPermissionException("This contest has not been started yet!"); } if (!hasPermission && (contest.ContestType == ContestType.Private || contest.ContestType == ContestType.RegisterPrivate)) { if (!ContestUserManager.ContestContainsUser(contest.ContestID, UserManager.CurrentUserName)) { throw new NoPermissionException("You have no privilege to view this contest!"); } } filterContext.ActionParameters["Contest"] = contest; ViewData["Contest"] = contest; }
public override void OnActionExecuting(ActionExecutingContext filterContext) { ContestEntity contest = filterContext.ActionParameters["Contest"] as ContestEntity; Boolean hasPermission = AdminManager.HasPermission(PermissionType.ContestManage); if (contest.EndTime < DateTime.Now) { throw new NoPermissionException("This contest has ended!"); } if (!hasPermission && contest.ContestType == ContestType.RegisterPublic) { if (!ContestUserManager.ContestContainsUser(contest.ContestID, UserManager.CurrentUserName)) { throw new NoPermissionException("You have no privilege to submit in this contest!"); } } }