/// <summary>
 /// 创建 ContestQueryParameter 类的新实例。
 /// </summary>
 public ContestQueryParameter()
 {
     Title            = string.Empty;
     QueryByTitle     = false;
     Creator          = string.Empty;
     QueryByCreator   = false;
     Status           = ContestStatus.Pending;
     QueryByStatus    = false;
     PageQuery        = new PageQueryParameter();
     EnablePagedQuery = false;
 }
        /// <summary>
        /// 初始化 UserQueryParameter 类的新实例。
        /// </summary>
        public UserQueryParameter()
        {
            QueryByOrganization = false;
            Organization        = string.Empty;

            QueryBySex = false;
            Sex        = UserSex.Male;

            QueryByUsergroup = false;
            UserGroup        = UserGroup.Administrators;

            EnablePageQuery = false;
            PageQuery       = new PageQueryParameter();
        }
Beispiel #3
0
 /// <summary>
 /// 创建 SubmissionQueryParameter 类的新实例。
 /// </summary>
 public SubmissionQueryParameter()
 {
     ProblemId         = string.Empty;
     QueryByProblemId  = false;
     Username          = string.Empty;
     QueryByUsername   = false;
     TeamId            = 0;
     QueryByTeamId     = false;
     Language          = SubmissionLanguage.GnuC;
     QueryByLanguage   = false;
     Verdict           = SubmissionVerdict.Accepted;
     QueryByVerdict    = false;
     OrderByDescending = true;
     PageQuery         = new PageQueryParameter();
     EnablePageQuery   = false;
 }
Beispiel #4
0
        /// <summary>
        /// 在给定的数据集上执行分页。
        /// </summary>
        /// <typeparam name="T">数据对象类型。</typeparam>
        /// <param name="query">原始可查询对象。</param>
        /// <param name="parameter">分页参数。</param>
        /// <returns>分页后的可查询对象。</returns>
        /// <exception cref="ArgumentNullException"/>
        /// <exception cref="ArgumentOutOfRangeException"/>
        public static IQueryable <T> Page <T>(this IQueryable <T> query, PageQueryParameter parameter)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }
            if (parameter.Page <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(parameter.Page));
            }
            if (parameter.ItemsPerPage <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(parameter.ItemsPerPage));
            }

            int totalPages = query.GetPages(parameter.ItemsPerPage);

            if (parameter.Page > totalPages)
            {
                throw new ArgumentOutOfRangeException(nameof(parameter.Page));
            }

            return(query.Skip(parameter.ItemsPerPage * (parameter.Page - 1)).Take(parameter.ItemsPerPage));
        }