Exemplo n.º 1
0
        /// <summary>
        /// 获取提交列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="cid">竞赛ID</param>
        /// <param name="pid">题目ID</param>
        /// <param name="userName">用户名</param>
        /// <param name="languageType">提交语言</param>
        /// <param name="resultType">提交结果</param>
        /// <param name="order">排序顺序</param>
        /// <returns>提交列表</returns>
        public static PagedList <SolutionEntity> GetSolutionList(Int32 pageIndex, Int32 cid, Int32 pid, String userName, String languageType, String resultType, String order)
        {
            Int32 pageSize             = SolutionManager.STATUS_PAGE_SIZE;
            Int32 recordCount          = 0;
            List <SolutionEntity> list = null;

            if (pid <= 0 && String.IsNullOrEmpty(userName) && String.IsNullOrEmpty(languageType) && String.IsNullOrEmpty(resultType))
            {
                recordCount = SolutionManager.CountSolutions(cid, -1, null, null, null);
                list        = SolutionRepository.Instance.GetEntities(cid, -1, null, LanguageType.Null, new Nullable <ResultType>(), -1,
                                                                      pageIndex, pageSize, recordCount);
            }
            else
            {
                if (!String.IsNullOrEmpty(userName) && (!RegexVerify.IsUserName(userName) || !SQLValidator.IsSafe(userName)))
                {
                    throw new InvalidInputException("Username is INVALID!");
                }
                if (!String.IsNullOrEmpty(languageType) && !RegexVerify.IsNumeric(languageType))
                {
                    throw new InvalidInputException("Language Type is INVALID!");
                }
                if (!String.IsNullOrEmpty(resultType) && !RegexVerify.IsNumeric(resultType))
                {
                    throw new InvalidInputException("Result Type is INVALID!");
                }

                recordCount = SolutionManager.CountSolutions(cid, pid, userName, languageType, resultType);
                list        = SolutionRepository.Instance.GetEntities(
                    cid, pid, userName,
                    (String.IsNullOrEmpty(languageType) ? LanguageType.Null : LanguageType.FromLanguageID(Convert.ToByte(languageType))),
                    (String.IsNullOrEmpty(resultType) ? new Nullable <ResultType>() : (ResultType)Convert.ToByte(resultType)),
                    (String.IsNullOrEmpty(order) ? -1 : Convert.ToInt32(order)),
                    pageIndex, pageSize, recordCount);
            }

            return(list.ToPagedList(pageSize, recordCount));
        }