예제 #1
0
        /// <summary>
        /// 创建 <see cref="AddictedUserList"/>
        /// </summary>
        /// <param name="currentUserId">当前登录用户 ID</param>
        /// <param name="steamAppId">Steam App ID</param>
        /// <param name="page">分页页码</param>
        /// <param name="dbContext"><see cref="KeylolDbContext"/></param>
        /// <param name="cachedData"><see cref="CachedDataProvider"/></param>
        /// <returns><see cref="AddictedUserList"/></returns>
        public static async Task <AddictedUserList> CreateAsync(string currentUserId, int?steamAppId, int page,
                                                                KeylolDbContext dbContext, CachedDataProvider cachedData)
        {
            var queryResult = await(from record in dbContext.UserSteamGameRecords
                                    where record.SteamAppId == steamAppId && record.UserId != currentUserId
                                    let isFriend =
                                        dbContext.Subscriptions.Any(
                                            s =>
                                            s.SubscriberId == currentUserId && s.TargetId == record.UserId &&
                                            s.TargetType == SubscriptionTargetType.User) &&
                                        dbContext.Subscriptions.Any(
                                            s =>
                                            s.SubscriberId == record.UserId && s.TargetId == currentUserId &&
                                            s.TargetType == SubscriptionTargetType.User)
                                        orderby isFriend descending, record.TotalPlayedTime descending
                                    select new
            {
                record.User.Id,
                record.User.HeaderImage,
                record.User.IdCode,
                record.User.AvatarImage,
                record.User.UserName,
                record.TotalPlayedTime,
                IsFriend = isFriend
            }).TakePage(page, 8).ToListAsync();

            var result = new AddictedUserList();

            foreach (var u in queryResult)
            {
                result.Add(new AddictedUser
                {
                    Id              = u.Id,
                    HeaderImage     = u.HeaderImage,
                    IdCode          = u.IdCode,
                    AvatarImage     = u.AvatarImage,
                    UserName        = u.UserName,
                    TotalPlayedTime = u.TotalPlayedTime,
                    IsFriend        = string.IsNullOrWhiteSpace(currentUserId) ? (bool?)null : u.IsFriend,
                    Subscribed      = string.IsNullOrWhiteSpace(currentUserId)
                        ? (bool?)null
                        : await cachedData.Subscriptions.IsSubscribedAsync(currentUserId, u.Id,
                                                                           SubscriptionTargetType.User)
                });
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// 创建 <see cref="FrontpagePage"/>
        /// </summary>
        /// <param name="point">已经查询好的据点对象</param>
        /// <param name="currentUserId">当前登录用户 ID</param>
        /// <param name="dbContext"><see cref="KeylolDbContext"/></param>
        /// <param name="cachedData"><see cref="CachedDataProvider"/></param>
        /// <returns><see cref="FrontpagePage"/></returns>
        public static async Task <FrontpagePage> CreateAsync(Models.Point point, string currentUserId,
                                                             KeylolDbContext dbContext, CachedDataProvider cachedData)
        {
            var frontPage = new FrontpagePage();

            if (point.Type == PointType.Game || point.Type == PointType.Hardware)
            {
                var briefReviews =
                    await BriefReviewList.CreateAsync(point, currentUserId, 1, true, dbContext, cachedData);

                frontPage.BriefReviewCount     = briefReviews.Item2;
                frontPage.BriefReviewPageCount = briefReviews.Item3;
                frontPage.BriefReviews         = briefReviews.Item1;
                frontPage.MediaHeaderImage     = point.MediaHeaderImage;
                frontPage.Media         = Helpers.SafeDeserialize <List <PointMedia> >(point.Media);
                frontPage.SimilarPoints =
                    await SimilarPointList.CreateAsync(point.Id, currentUserId, 1, dbContext, cachedData);

                frontPage.SelectedArticles =
                    await SelectedArticleList.CreateAsync(point.Id, 1, 4, currentUserId, dbContext, cachedData);
            }

            if (point.Type == PointType.Game)
            {
                frontPage.Platforms = await(from relationship in dbContext.PointRelationships
                                            where relationship.SourcePointId == point.Id &&
                                            relationship.Relationship == PointRelationshipType.Platform
                                            orderby relationship.Sid descending
                                            select relationship.TargetPoint.IdCode)
                                      .ToListAsync();

                #region 特性属性

                frontPage.MultiPlayer         = point.MultiPlayer ? true : (bool?)null;
                frontPage.SinglePlayer        = point.SinglePlayer ? true : (bool?)null;
                frontPage.Coop                = point.Coop ? true : (bool?)null;
                frontPage.CaptionsAvailable   = point.CaptionsAvailable ? true : (bool?)null;
                frontPage.CommentaryAvailable = point.CommentaryAvailable ? true : (bool?)null;
                frontPage.IncludeLevelEditor  = point.IncludeLevelEditor ? true : (bool?)null;
                frontPage.Achievements        = point.Achievements ? true : (bool?)null;
                frontPage.Cloud               = point.Cloud ? true : (bool?)null;
                frontPage.LocalCoop           = point.LocalCoop ? true : (bool?)null;
                frontPage.SteamTradingCards   = point.SteamTradingCards ? true : (bool?)null;
                frontPage.SteamWorkshop       = point.SteamWorkshop ? true : (bool?)null;
                frontPage.InAppPurchases      = point.InAppPurchases ? true : (bool?)null;

                #endregion

                frontPage.ChineseAvailability = Helpers.SafeDeserialize <ChineseAvailability>(point.ChineseAvailability);

                if (point.SteamAppId != null)
                {
                    frontPage.AddictedUsers =
                        await AddictedUserList.CreateAsync(currentUserId, point.SteamAppId, 1, dbContext, cachedData);
                }
            }
            else if (point.Type == PointType.Vendor)
            {
                var developerProducts = await ProductPointList.CreateAsync(currentUserId, point.Id,
                                                                           PointRelationshipType.Developer, 3, dbContext, cachedData);

                frontPage.DeveloperProducts     = developerProducts.Item1;
                frontPage.DeveloperProductCount = developerProducts.Item2;

                var publisherProducts = await ProductPointList.CreateAsync(currentUserId, point.Id,
                                                                           PointRelationshipType.Publisher, 3, dbContext, cachedData);

                frontPage.PublisherProducts     = publisherProducts.Item1;
                frontPage.PublisherProductCount = publisherProducts.Item2;

                var resellerProducts = await ProductPointList.CreateAsync(currentUserId, point.Id,
                                                                          PointRelationshipType.Reseller, 3, dbContext, cachedData);

                frontPage.ResellerProducts     = resellerProducts.Item1;
                frontPage.ResellerProductCount = resellerProducts.Item2;

                var manufacturerProducts = await ProductPointList.CreateAsync(currentUserId, point.Id,
                                                                              PointRelationshipType.Manufacturer, 3, dbContext, cachedData);

                frontPage.ManufacturerProducts     = manufacturerProducts.Item1;
                frontPage.ManufacturerProductCount = manufacturerProducts.Item2;
            }
            else if (point.Type == PointType.Category)
            {
                var tagProducts = await ProductPointList.CreateAsync(currentUserId, point.Id,
                                                                     PointRelationshipType.Tag, 3, dbContext, cachedData);

                frontPage.TagProducts     = tagProducts.Item1;
                frontPage.TagProductCount = tagProducts.Item2;

                var seriesProducts = await ProductPointList.CreateAsync(currentUserId, point.Id,
                                                                        PointRelationshipType.Series, 3, dbContext, cachedData);

                frontPage.SeriesProducts     = seriesProducts.Item1;
                frontPage.SeriesProductCount = seriesProducts.Item2;

                var genreProducts = await ProductPointList.CreateAsync(currentUserId, point.Id,
                                                                       PointRelationshipType.Genre, 3, dbContext, cachedData);

                frontPage.GenreProducts     = genreProducts.Item1;
                frontPage.GenreProductCount = genreProducts.Item2;
            }
            else if (point.Type == PointType.Platform)
            {
                var platformProducts = await ProductPointList.CreateAsync(currentUserId, point.Id,
                                                                          PointRelationshipType.Platform, 3, dbContext, cachedData);

                frontPage.PlatformProducts = platformProducts.Item1;
            }

            var latestArticles = await LatestArticleList.CreateAsync(point.Id, 1, true, true, dbContext, cachedData);

            frontPage.LatestArticleHeaderImage = latestArticles.Item3;
            frontPage.LatestArticlePageCount   = latestArticles.Item2;
            frontPage.LatestArticles           = latestArticles.Item1;

            return(frontPage);
        }