/// <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())); }
/// <summary> /// 使用指定的题目 ID 查询该题目的类别实体对象数据。 /// </summary> /// <param name="problemId">要查询的题目的题目 ID 。</param> /// <returns>一个列表,该列表包含了给定题目的所有类别实体对象。</returns> /// <exception cref="ArgumentNullException"/> public IList <ProblemCategoryEntity> QueryProblemCategoryEntities(string problemId) { if (problemId == null) { throw new ArgumentNullException(nameof(problemId)); } // 将 problemId 处理为大写表示以方便数据库查询。 problemId = problemId.ToUpper(); // 收集 problemId 所对应的题目的类别对象的主键值。 var entities = from item in Relations where item.ProblemId == problemId select item.CategoryId; // 查询类别对象主键值并得到类别实体对象。 List <ProblemCategoryEntity> ret = new List <ProblemCategoryEntity>(); foreach (int id in entities) { ProblemCategoryEntity item = QueryCategoryEntity(id); if (item != null) { ret.Add(item); } } return(ret); }
/// <summary> /// 将给定的题目类别实体对象添加至数据集中。 /// </summary> /// <param name="entity">要添加的题目类别实体对象。</param> /// <exception cref="ArgumentNullException"/> public void AddProblemCategory(ProblemCategoryEntity entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } Categories.Add(entity); }
/// <summary> /// 题目分类添加页面 /// </summary> /// <returns>操作后的结果</returns> public ActionResult CategoryAdd() { ProblemCategoryEntity entity = new ProblemCategoryEntity() { Order = 255 }; return(View("CategoryEdit", entity)); }
/// <summary> /// 从数据集中移除给定题目类别实体对象。 /// </summary> /// <param name="entity">要移除的题目类别实体对象。</param> /// <exception cref="ArgumentNullException"/> public void RemoveCategoryEntity(ProblemCategoryEntity entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } Categories.Remove(entity); SaveChanges(); }
public ActionResult CategoryAdd(FormCollection form) { ProblemCategoryEntity entity = new ProblemCategoryEntity() { Title = form["title"], Order = form["order"].ToInt32(0) }; return(ResultToMessagePage(ProblemCategoryManager.AdminInsertProblemCategory, entity, "Your have added problem category successfully!")); }
public ActionResult CategoryEdit(Int32 id, FormCollection form) { ProblemCategoryEntity entity = new ProblemCategoryEntity() { TypeID = id, Title = form["title"], Order = form["order"].ToInt32(0) }; return(ResultToMessagePage(ProblemCategoryManager.AdminUpdateProblemCategory, entity, "Your have edited problem category successfully!")); }
/// <summary> /// 将给定的题目类别实体对象添加到数据集中。 /// </summary> /// <param name="entity">要添加的题目类别实体对象。</param> /// <exception cref="ArgumentNullException"/> public void AddProblemCategoryEntity(ProblemCategoryEntity entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } entity.Name = entity.Name.ToUpper(); Categories.Add(entity); SaveChanges(); }
/// <summary> /// 根据ID得到题目类型种类实体 /// </summary> /// <param name="id">题目类型种类ID</param> /// <returns>题目类型种类实体</returns> public static IMethodResult AdminGetProblemCategory(Int32 id) { if (!AdminManager.HasPermission(PermissionType.ProblemManage)) { throw new NoPermissionException(); } if (id <= 0) { return(MethodResult.InvalidRequest(RequestType.ProblemCategory)); } ProblemCategoryEntity entity = ProblemCategoryRepository.Instance.GetEntity(id); if (entity == null) { return(MethodResult.NotExist(RequestType.ProblemCategory)); } return(MethodResult.Success(entity)); }
/// <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)); }