Exemplo n.º 1
0
        /// <summary>
        /// 更新一条题目类型种类
        /// </summary>
        /// <param name="entity">题目类型种类实体</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateProblemCategory(ProblemCategoryEntity entity)
        {
            if (!AdminManager.HasPermission(PermissionType.ProblemManage))
            {
                throw new NoPermissionException();
            }

            if (entity.TypeID <= 0)
            {
                return(MethodResult.InvalidRequest(RequestType.ProblemCategory));
            }

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

            Boolean success = ProblemCategoryRepository.Instance.UpdateEntity(entity) > 0;

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

            ProblemCategoryCache.RemoveProblemCategoryListCache();//删除缓存

            return(MethodResult.SuccessAndLog("Admin update problem category, id = {0}", entity.TypeID.ToString()));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 删除指定ID的题目类型种类
        /// </summary>
        /// <param name="id">题目类型种类ID</param>
        /// <returns>是否成功删除</returns>
        public static IMethodResult AdminDeleteProblemCategory(Int32 id)
        {
            if (!AdminManager.HasPermission(PermissionType.ProblemManage))
            {
                throw new NoPermissionException();
            }

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

            if (ProblemCategoryItemRepository.Instance.CountEntities(id) > 0)
            {
                return(MethodResult.FailedAndLog("This category still has some problems, please remove these problem from this category first!"));
            }

            Boolean success = ProblemCategoryRepository.Instance.DeleteEntity(id) > 0;

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

            ProblemCategoryCache.RemoveProblemCategoryListCache();//删除缓存

            return(MethodResult.SuccessAndLog("Admin delete problem category, id = {0}", id.ToString()));
        }
Exemplo n.º 3
0
        ///// <summary>
        ///// 根据ID得到一个题目类型种类实体
        ///// </summary>
        ///// <param name="id">题目类型种类ID</param>
        ///// <returns>题目类型种类实体</returns>
        //public static ProblemCategoryEntity GetProblemCategory(Int32 id)
        //{
        //    if (id <= 0)
        //    {
        //        throw new InvalidRequstException(RequestType.ProblemCategory);
        //    }

        //    List<ProblemCategoryEntity> list = ProblemCategoryManager.GetProblemCategoryList();

        //    if (list != null && list.Count > 0)
        //    {
        //        for (Int32 i = 0; i < list.Count; i++)
        //        {
        //            if (list[i].TypeID == id) return list[i];
        //        }
        //    }

        //    throw new NullResponseException(RequestType.ProblemCategory);
        //}

        /// <summary>
        /// 获取所有题目类型种类
        /// </summary>
        /// <returns>所有题目类型种类</returns>
        public static List <ProblemCategoryEntity> GetProblemCategoryList()
        {
            List <ProblemCategoryEntity> list = ProblemCategoryCache.GetProblemCategoryListCache();//获取缓存

            if (list == null)
            {
                list = ProblemCategoryRepository.Instance.GetAllEntities();
                ProblemCategoryCache.SetProblemCategoryListCache(list);//设置缓存
            }

            return(list);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 增加一条题目类型种类
        /// </summary>
        /// <param name="entity">题目类型种类实体</param>
        /// <returns>是否成功增加</returns>
        public static IMethodResult AdminInsertProblemCategory(ProblemCategoryEntity entity)
        {
            if (!AdminManager.HasPermission(PermissionType.ProblemManage))
            {
                throw new NoPermissionException();
            }

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

            Boolean success = ProblemCategoryRepository.Instance.InsertEntity(entity) > 0;

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

            ProblemCategoryCache.RemoveProblemCategoryListCache();//删除缓存

            return(MethodResult.SuccessAndLog("Admin add problem category, title = {0}", entity.Title));
        }