/// <summary> /// 增加一条提交 /// </summary> /// <param name="entity">对象实体</param> /// <param name="userip">用户IP</param> /// <returns>是否成功增加</returns> public static Boolean InsertSolution(SolutionEntity entity, String userip) { if (!UserManager.IsUserLogined) { throw new UserUnLoginException(); } if (String.IsNullOrEmpty(entity.SourceCode) || entity.SourceCode.Length < SolutionRepository.SOURCECODE_MINLEN) { throw new InvalidInputException("Code is too short!"); } if (entity.SourceCode.Length > SolutionRepository.SOURCECODE_MAXLEN) { throw new InvalidInputException("Code is too long!"); } if (LanguageType.IsNull(entity.LanguageType)) { throw new InvalidInputException("Language Type is INVALID!"); } if (!UserSubmitStatus.CheckLastSubmitSolutionTime(UserManager.CurrentUserName)) { throw new InvalidInputException(String.Format("You can not submit code more than twice in {0} seconds!", ConfigurationManager.SubmitInterval.ToString())); } ProblemEntity problem = ProblemManager.InternalGetProblemModel(entity.ProblemID); if (problem == null)//判断题目是否存在 { throw new NullResponseException(RequestType.Problem); } if (entity.ContestID <= 0 && problem.IsHide && !AdminManager.HasPermission(PermissionType.ProblemManage))//非竞赛下判断是否有权访问题目 { throw new NoPermissionException("You have no privilege to submit the problem!"); } entity.UserName = UserManager.CurrentUserName; entity.SubmitTime = DateTime.Now; entity.SubmitIP = userip; Boolean success = SolutionRepository.Instance.InsertEntity(entity) > 0; if (success) { ProblemCache.UpdateProblemCacheSubmitCount(entity.ProblemID, -1);//更新缓存 SolutionCache.RemoveProblemIDListCache(entity.UserName, true); } return(success); }
/// <summary> /// 根据ID得到一个题目实体 /// </summary> /// <param name="id">题目ID</param> /// <returns>题目实体</returns> public static ProblemEntity GetProblem(Int32 id) { if (id < ConfigurationManager.ProblemSetStartID) { throw new InvalidRequstException(RequestType.Problem); } ProblemEntity problem = ProblemManager.InternalGetProblemModel(id); if (problem == null) { throw new NullResponseException(RequestType.Problem); } if (problem.IsHide && !AdminManager.HasPermission(PermissionType.ProblemManage)) { throw new NoPermissionException("You have no privilege to view the problem!"); } return(problem); }