/// <summary> /// 题目添加页面 /// </summary> /// <returns>操作后的结果</returns> public ActionResult Add() { ProblemEntity entity = new ProblemEntity() { TimeLimit = 1000, MemoryLimit = 32768 }; return View("Edit", entity); }
public ActionResult Add(FormCollection form) { ProblemEntity entity = new ProblemEntity() { Title = form["title"], Description = form["description"], Input = form["input"], Output = form["output"], SampleInput = form["samplein"], SampleOutput = form["sampleout"], Hint = form["hint"], Source = form["source"], TimeLimit = form["timelimit"].ToInt32(1000), MemoryLimit = form["memorylimit"].ToInt32(32768) }; return ResultToMessagePage(ProblemManager.AdminInsertProblem, entity, "Your have added problem successfully!"); }
/// <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()); }
/// <summary> /// 增加一条题目 /// </summary> /// <param name="entity">题目实体</param> /// <returns>是否成功增加</returns> public static IMethodResult AdminInsertProblem(ProblemEntity entity) { if (!AdminManager.HasPermission(PermissionType.ProblemManage)) { throw new NoPermissionException(); } 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.IsHide = true; entity.LastDate = DateTime.Now; Boolean success = ProblemRepository.Instance.InsertEntity(entity) > 0; if (!success) { return MethodResult.FailedAndLog("No problem was added!"); } ProblemCache.IncreaseProblemSetCountCache();//更新缓存 ProblemCache.IncreaseProblemIDMaxCache();//更新缓存 ProblemCache.RemoveProblemSetCache(GetProblemPageIndex(entity.ProblemID));//删除缓存 return MethodResult.SuccessAndLog("Admin add problem, title = {0}", entity.Title); }
/// <summary> /// 向缓存中写入指定竞赛题目信息 /// </summary> /// <param name="cid">竞赛ID</param> /// <param name="pid">题目ID</param> /// <param name="problem">竞赛题目信息</param> public static void SetContestProblemCache(Int32 cid, Int32 pid, ProblemEntity problem) { if (problem != null) CacheManager.Set(GetContestProblemCacheKey(cid, pid), problem, CONTEST_PROBLEM_CACHE_TIME); }