Example #1
0
        /// <summary>
        /// 根据指定的队伍查询参数查询队伍句柄。
        /// </summary>
        /// <param name="query">查询参数。</param>
        /// <returns>查询到的队伍句柄结果对象。</returns>
        /// <exception cref="ArgumentNullException"/>
        public ReadOnlyCollection <TeamHandle> QueryTeams(TeamQueryParameter query)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }
            if (query.QueryByName && query.Name == null)
            {
                throw new ArgumentNullException(nameof(query.Name));
            }
            if (query.QueryByLeader && query.Leader == null)
            {
                throw new ArgumentNullException(nameof(query.Leader));
            }

            return(m_factory.WithContext(context =>
            {
                IQueryable <TeamProfileEntity> set = context.GetAllTeamProfiles();
                if (query.QueryByName)
                {
                    set = UserDataContext.QueryTeamProfileEntityByName(set, query.Name);
                }
                if (query.QueryByLeader)
                {
                    set = UserDataContext.QueryTeamProfileEntityByLeader(set, query.Leader);
                }

                // 对查询结果进行排序以准备分页。
                set = set.OrderBy(ent => ent.Id);

                if (query.EnablePageQuery)
                {
                    set = set.Page(query.PageQuery);
                }

                List <TeamHandle> handles = new List <TeamHandle>();
                foreach (TeamProfileEntity ent in set)
                {
                    handles.Add(TeamHandle.FromTeamEntity(ent));
                }

                return new ReadOnlyCollection <TeamHandle>(handles);
            }));
        }