/// <summary>
        /// 创建 <see cref="RecentPlayedPointList"/>
        /// </summary>
        /// <param name="currentUserId">当前登录用户 ID</param>
        /// <param name="dbContext"><see cref="KeylolDbContext"/></param>
        /// <param name="cachedData"><see cref="CachedDataProvider"/></param>
        /// <returns>Item1 表示 <see cref="RecentPlayedPointList"/>,Item2 表示第一个据点头部图</returns>
        public static async Task <Tuple <RecentPlayedPointList, string> > CreateAsync(string currentUserId,
                                                                                      KeylolDbContext dbContext, CachedDataProvider cachedData)
        {
            var queryResult = await(string.IsNullOrWhiteSpace(currentUserId)
                ? from point in dbContext.Points
                                    where DbFunctions.DiffMonths(point.CreateTime, DateTime.Now) <= 3 &&
                                    (point.Type == PointType.Game || point.Type == PointType.Hardware)
                                    orderby dbContext.Subscriptions
                                    .Count(s => s.TargetId == point.Id && s.TargetType == SubscriptionTargetType.Point) descending,
                                    point.LastActivityTime descending
                                    select new
            {
                point.Id,
                point.IdCode,
                point.HeaderImage,
                point.ThumbnailImage,
                point.ChineseName,
                point.EnglishName,
                TwoWeekPlayedTime = (double?)null
            }
                : from record in dbContext.UserSteamGameRecords
                                    where record.UserId == currentUserId
                                    join point in dbContext.Points on record.SteamAppId equals point.SteamAppId
                                    where !dbContext.Subscriptions.Any(s =>
                                                                       s.SubscriberId == currentUserId && s.TargetId == point.Id &&
                                                                       s.TargetType == SubscriptionTargetType.Point)
                                    orderby record.TwoWeekPlayedTime descending, record.LastPlayTime descending
                                    select new
            {
                point.Id,
                point.IdCode,
                point.HeaderImage,
                point.ThumbnailImage,
                point.ChineseName,
                point.EnglishName,
                TwoWeekPlayedTime = (double?)record.TwoWeekPlayedTime
            }
                                    ).Take(5).ToListAsync();
            var result = new RecentPlayedPointList(queryResult.Count);

            foreach (var p in queryResult)
            {
                result.Add(new RecentPlayedPoint
                {
                    Id                = p.Id,
                    IdCode            = p.IdCode,
                    ThumbnailImage    = p.ThumbnailImage,
                    ChineseName       = p.ChineseName,
                    EnglishName       = p.EnglishName,
                    AverageRating     = (await cachedData.Points.GetRatingsAsync(p.Id)).AverageRating,
                    TwoWeekPlayedTime = p.TwoWeekPlayedTime
                });
            }
            var firstRecord = queryResult.FirstOrDefault(p => !string.IsNullOrWhiteSpace(p.HeaderImage));

            return(new Tuple <RecentPlayedPointList, string>(
                       result,
                       firstRecord?.HeaderImage));
        }
示例#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
            });
        }