Example #1
0
        /// <summary>
        /// 根据ID得到一个题目实体
        /// </summary>
        /// <param name="id">题目ID</param>
        /// <returns>题目实体</returns>
        public static IMethodResult AdminGetProblem(Int32 id)
        {
            if (!AdminManager.HasPermission(PermissionType.ProblemManage))
            {
                throw new NoPermissionException();
            }

            if (id < ConfigurationManager.ProblemSetStartID)
            {
                return(MethodResult.InvalidRequest(RequestType.Problem));
            }

            ProblemEntity entity = ProblemRepository.Instance.GetEntity(id);

            if (entity == null)
            {
                return(MethodResult.NotExist(RequestType.Problem));
            }

            return(MethodResult.Success(entity));
        }
Example #2
0
        /// <summary>
        /// 根据ID得到一个竞赛实体
        /// </summary>
        /// <param name="id">竞赛ID</param>
        /// <returns>竞赛实体</returns>
        public static IMethodResult AdminGetContest(Int32 id)
        {
            if (!AdminManager.HasPermission(PermissionType.ContestManage))
            {
                throw new NoPermissionException();
            }

            if (id < ContestRepository.NONECONTEST)
            {
                return(MethodResult.InvalidRequest(RequestType.Contest));
            }

            ContestEntity entity = ContestRepository.Instance.GetEntity(id);

            if (entity == null)
            {
                return(MethodResult.NotExist(RequestType.Contest));
            }

            return(MethodResult.Success(entity));
        }
Example #3
0
        /// <summary>
        /// 根据ID得到一个对象实体
        /// </summary>
        /// <param name="resourceID">实体ID</param>
        /// <returns>对象实体</returns>
        public static IMethodResult AdminGetResource(Int32 id)
        {
            if (!AdminManager.HasPermission(PermissionType.ResourceManage))
            {
                throw new NoPermissionException();
            }

            if (id <= 0)
            {
                return(MethodResult.InvalidRequest(RequestType.Resource));
            }

            ResourceEntity entity = ResourceRepository.Instance.GetEntity(id);

            if (entity == null)
            {
                return(MethodResult.NotExist(RequestType.Resource));
            }

            return(MethodResult.Success(entity));
        }
Example #4
0
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <returns>用户实体</returns>
        public static IMethodResult AdminGetUserInfo(String userName)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsUserName(userName))
            {
                return(MethodResult.InvalidRequest(RequestType.User));
            }

            UserEntity entity = UserRepository.Instance.GetEntityWithAllInfo(userName);

            if (entity == null)
            {
                return(MethodResult.NotExist(RequestType.User));
            }

            return(MethodResult.Success(entity));
        }
Example #5
0
        /// <summary>
        /// 根据ID得到一个主题页面实体
        /// </summary>
        /// <param name="id">主题页面ID</param>
        /// <returns>主题页面实体</returns>
        public static IMethodResult AdminGetTopicPage(String name)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsPageName(name))
            {
                return(MethodResult.InvalidRequest(RequestType.TopicPage));
            }

            TopicPageEntity entity = TopicPageRepository.Instance.GetEntity(name);

            if (entity == null)
            {
                return(MethodResult.NotExist(RequestType.TopicPage));
            }

            return(MethodResult.Success(entity));
        }