예제 #1
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
            });
        }
예제 #2
0
        /// <summary>
        /// 创建 <see cref="OutpostPointList"/>
        /// </summary>
        /// <param name="currentUserId">当前登录用户 ID</param>
        /// <param name="page">分页页码</param>
        /// <param name="recordsPerPage">每页数量</param>
        /// <param name="dbContext"><see cref="KeylolDbContext"/></param>
        /// <param name="cachedData"><see cref="CachedDataProvider"/></param>
        /// <returns><see cref="OutpostPointList"/></returns>
        public static async Task <OutpostPointList> CreateAsync(string currentUserId, int page, int recordsPerPage,
                                                                KeylolDbContext dbContext, CachedDataProvider cachedData)
        {
            var queryResult = await(from feed in dbContext.Feeds
                                    where feed.StreamName == OutpostStream.Name
                                    join point in dbContext.Points on feed.Entry equals point.Id
                                    orderby feed.Id descending
                                    select new
            {
                FeedId = feed.Id,
                point.Id,
                point.IdCode,
                point.AvatarImage,
                point.ChineseName,
                point.EnglishName,
                point.TitleCoverImage,
                point.MultiPlayer,
                point.SinglePlayer,
                point.Coop,
                point.CaptionsAvailable,
                point.CommentaryAvailable,
                point.IncludeLevelEditor,
                point.Achievements,
                point.Cloud,
                point.LocalCoop,
                point.SteamTradingCards,
                point.SteamWorkshop,
                point.InAppPurchases,
                point.SteamAppId,
                point.SteamPrice,
                point.SteamDiscountedPrice,
                point.SonkwoProductId,
                point.SonkwoPrice,
                point.SonkwoDiscountedPrice,
                point.UplayLink,
                point.UplayPrice,
                point.XboxLink,
                point.XboxPrice,
                point.PlayStationLink,
                point.PlayStationPrice,
                point.OriginLink,
                point.OriginPrice,
                point.WindowsStoreLink,
                point.WindowsStorePrice,
                point.AppStoreLink,
                point.AppStorePrice,
                point.GooglePlayLink,
                point.GooglePlayPrice,
                point.GogLink,
                point.GogPrice,
                point.BattleNetLink,
                point.BattleNetPrice,
                Categories = (from relationship in dbContext.PointRelationships
                              where relationship.SourcePointId == point.Id &&
                              relationship.Relationship == PointRelationshipType.Tag
                              select new
                {
                    relationship.TargetPoint.IdCode,
                    relationship.TargetPoint.ChineseName,
                    relationship.TargetPoint.EnglishName
                }).ToList()
            })
                              .TakePage(page, recordsPerPage)
                              .ToListAsync();
            var result = new OutpostPointList(queryResult.Count);

            foreach (var p in queryResult)
            {
                result.Add(new OutpostPoint
                {
                    FeedId                = p.FeedId,
                    Id                    = p.Id,
                    IdCode                = p.IdCode,
                    AvatarImage           = p.AvatarImage,
                    ChineseName           = p.ChineseName,
                    EnglishName           = p.EnglishName,
                    AverageRating         = (await cachedData.Points.GetRatingsAsync(p.Id)).AverageRating,
                    TitleCoverImage       = p.TitleCoverImage,
                    MultiPlayer           = p.MultiPlayer ? true : (bool?)null,
                    SinglePlayer          = p.SinglePlayer ? true : (bool?)null,
                    Coop                  = p.Coop ? true : (bool?)null,
                    CaptionsAvailable     = p.CaptionsAvailable ? true : (bool?)null,
                    CommentaryAvailable   = p.CommentaryAvailable ? true : (bool?)null,
                    IncludeLevelEditor    = p.IncludeLevelEditor ? true : (bool?)null,
                    Achievements          = p.Achievements ? true : (bool?)null,
                    Cloud                 = p.Cloud ? true : (bool?)null,
                    LocalCoop             = p.LocalCoop ? true : (bool?)null,
                    SteamTradingCards     = p.SteamTradingCards ? true : (bool?)null,
                    SteamWorkshop         = p.SteamWorkshop ? true : (bool?)null,
                    InAppPurchases        = p.InAppPurchases ? true : (bool?)null,
                    SteamAppId            = p.SteamAppId,
                    SteamPrice            = p.SteamPrice,
                    SteamDiscountedPrice  = p.SteamDiscountedPrice,
                    SonkwoProductId       = p.SonkwoProductId,
                    SonkwoPrice           = p.SonkwoPrice,
                    SonkwoDiscountedPrice = p.SonkwoDiscountedPrice,
                    UplayLink             = p.UplayLink,
                    UplayPrice            = p.UplayPrice,
                    XboxLink              = p.XboxLink,
                    XboxPrice             = p.XboxPrice,
                    PlayStationLink       = p.PlayStationLink,
                    PlayStationPrice      = p.PlayStationPrice,
                    OriginLink            = p.OriginLink,
                    OriginPrice           = p.OriginPrice,
                    WindowsStoreLink      = p.WindowsStoreLink,
                    WindowsStorePrice     = p.WindowsStorePrice,
                    AppStoreLink          = p.AppStoreLink,
                    AppStorePrice         = p.AppStorePrice,
                    GooglePlayLink        = p.GooglePlayLink,
                    GooglePlayPrice       = p.GooglePlayPrice,
                    GogLink               = p.GogLink,
                    GogPrice              = p.GogPrice,
                    BattleNetLink         = p.BattleNetLink,
                    BattleNetPrice        = p.BattleNetPrice,
                    Categories            = p.Categories.Select(c => new PointBasicInfo
                    {
                        IdCode      = c.IdCode,
                        ChineseName = string.IsNullOrWhiteSpace(c.ChineseName) ? c.EnglishName : c.ChineseName
                    }).ToList(),
                    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)
                });
            }
            return(result);
        }