/// <summary>
        /// 创建 <see cref="RecentPointList"/>
        /// </summary>
        /// <param name="currentUserId">当前登录用户 ID</param>
        /// <param name="page">分页页码</param>
        /// <param name="returnPageCount">是否返回总页数</param>
        /// <param name="dbContext"><see cref="KeylolDbContext"/></param>
        /// <param name="cachedData"><see cref="CachedDataProvider"/></param>
        /// <returns>Item1 表示 <see cref="RecentPointList"/>,Item2 表示总页数</returns>
        public static async Task <Tuple <RecentPointList, int> > CreateAsync(string currentUserId, int page,
                                                                             bool returnPageCount, KeylolDbContext dbContext, CachedDataProvider cachedData)
        {
            var conditionQuery = from point in dbContext.Points
                                 where point.Type == PointType.Game || point.Type == PointType.Hardware
                                 orderby point.LastActivityTime descending
                                 select point;
            var queryResult = await conditionQuery.Select(p => new
            {
                Count = returnPageCount ? conditionQuery.Count() : 1,
                p.Id,
                p.Type,
                p.IdCode,
                p.AvatarImage,
                p.ChineseName,
                p.EnglishName,
                p.TitleCoverImage,
                p.SteamAppId
            }).TakePage(page, RecordsPerPage).ToListAsync();

            var result = new RecentPointList(queryResult.Count);

            foreach (var p in queryResult)
            {
                result.Add(new PointBasicInfo
                {
                    Id              = p.Id,
                    Type            = p.Type,
                    IdCode          = p.IdCode,
                    AvatarImage     = p.AvatarImage,
                    ChineseName     = p.ChineseName,
                    EnglishName     = p.EnglishName,
                    TitleCoverImage = p.TitleCoverImage,
                    AverageRating   = (await cachedData.Points.GetRatingsAsync(p.Id)).AverageRating,
                    Subscribed      = string.IsNullOrWhiteSpace(currentUserId)
                        ? (bool?)null
                        : await cachedData.Subscriptions.IsSubscribedAsync(currentUserId, p.Id,
                                                                           SubscriptionTargetType.Point),
                    InLibrary = string.IsNullOrWhiteSpace(currentUserId) || p.SteamAppId == null
                        ? (bool?)null
                        : await cachedData.Users.IsSteamAppInLibraryAsync(currentUserId, p.SteamAppId.Value)
                });
            }
            var firstRecord = queryResult.FirstOrDefault();

            return(new Tuple <RecentPointList, int>(
                       result,
                       (int)Math.Ceiling(firstRecord?.Count / (double)RecordsPerPage ?? 1)));
        }
Example #2
0
        /// <summary>
        /// 创建 <see cref="PointsPage"/>
        /// </summary>
        /// <param name="currentUserId">当前登录用户 ID</param>
        /// <param name="dbContext"><see cref="KeylolDbContext"/></param>
        /// <param name="cachedData"><see cref="CachedDataProvider"/></param>
        /// <returns><see cref="PointsPage"/></returns>
        public static async Task <PointsPage> CreateAsync(string currentUserId, KeylolDbContext dbContext,
                                                          CachedDataProvider cachedData)
        {
            var recentPlayedPoints = await RecentPlayedPointList.CreateAsync(currentUserId, dbContext, cachedData);

            var recentPoints = await RecentPointList.CreateAsync(currentUserId, 1, true, dbContext, cachedData);

            return(new PointsPage
            {
                OutpostPoints = await OutpostPointList.CreateAsync(currentUserId, 1, 15, dbContext, cachedData),
                RecentPlayedPointHeaderImage = recentPlayedPoints.Item2,
                RecentPlayedPoints = recentPlayedPoints.Item1,
                InterestedPoints = await InterestedPointList.CreateAsync(currentUserId, 1, dbContext),
                SpotlightUsers = await SpotlightUserList.CreateAsync(currentUserId, 1, dbContext),
                RecentPointPageCount = recentPoints.Item2,
                RecentPoints = recentPoints.Item1
            });
        }