示例#1
0
        /// <summary>
        /// 更新题目通过总数
        /// </summary>
        /// <param name="problemID">题目ID</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateProblemSolvedCount(Int32 problemID)
        {
            if (!AdminManager.HasPermission(PermissionType.ProblemManage))
            {
                throw new NoPermissionException();
            }

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

            Boolean success = ProblemRepository.Instance.UpdateEntitySolvedCount(problemID) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No problem's solved count was recalculated!"));
            }

            ProblemCache.RemoveProblemCache(problemID);                         //删除缓存
            ProblemCache.RemoveProblemSetCache(GetProblemPageIndex(problemID)); //删除缓存

            return(MethodResult.SuccessAndLog("Admin update problem's solved count, id = {0}", problemID.ToString()));
        }
示例#2
0
        /// <summary>
        /// 更新题目信息
        /// </summary>
        /// <param name="entity">对象实体</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateProblem(ProblemEntity entity)
        {
            if (!AdminManager.HasPermission(PermissionType.ProblemManage))
            {
                throw new NoPermissionException();
            }

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

            if (String.IsNullOrEmpty(entity.Title))
            {
                return(MethodResult.FailedAndLog("Problem title cannot be NULL!"));
            }

            if (String.IsNullOrEmpty(entity.Description))
            {
                return(MethodResult.FailedAndLog("Problem description cannot be NULL!"));
            }

            if (String.IsNullOrEmpty(entity.Input))
            {
                return(MethodResult.FailedAndLog("Problem input cannot be NULL!"));
            }

            if (String.IsNullOrEmpty(entity.Output))
            {
                return(MethodResult.FailedAndLog("Problem output cannot be NULL!"));
            }

            if (String.IsNullOrEmpty(entity.SampleInput))
            {
                return(MethodResult.FailedAndLog("Problem sample input cannot be NULL!"));
            }

            if (String.IsNullOrEmpty(entity.SampleOutput))
            {
                return(MethodResult.FailedAndLog("Problem sample output cannot be NULL!"));
            }

            if (entity.TimeLimit <= 0)
            {
                return(MethodResult.FailedAndLog("Time limit must not be less or equal than zero!"));
            }

            if (entity.MemoryLimit <= 0)
            {
                return(MethodResult.FailedAndLog("Memory limit must not be less or equal than zero!"));
            }

            entity.LastDate = DateTime.Now;
            Boolean success = ProblemRepository.Instance.UpdateEntity(entity) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No problem was updated!"));
            }

            ProblemCache.RemoveProblemCache(entity.ProblemID);//删除缓存
            ProblemCache.RemoveProblemSetCache(GetProblemPageIndex(entity.ProblemID));

            return(MethodResult.SuccessAndLog("Admin update problem, id = {0}", entity.ProblemID.ToString()));
        }