コード例 #1
0
        /// <summary>
        /// 创建 <see cref="SimilarPointList"/>
        /// </summary>
        /// <param name="pointId">据点 ID</param>
        /// <param name="currentUserId">当点登录用户 ID</param>
        /// <param name="page">分页页码</param>
        /// <param name="dbContext"><see cref="KeylolDbContext"/></param>
        /// <param name="cachedData"><see cref="CachedDataProvider"/></param>
        /// <returns><see cref="SimilarPointList"/></returns>
        public static async Task <SimilarPointList> CreateAsync(string pointId, string currentUserId, int page,
                                                                KeylolDbContext dbContext, CachedDataProvider cachedData)
        {
            var queryResult = await(from relationship in dbContext.PointRelationships
                                    where dbContext.PointRelationships.Where(r => r.SourcePointId == pointId).Select(r => r.TargetPointId)
                                    .Contains(relationship.TargetPointId) && relationship.SourcePointId != pointId
                                    group 1 by relationship.SourcePoint
                                    into g
                                    orderby g.Count() descending
                                    select new
            {
                g.Key.Id,
                g.Key.IdCode,
                g.Key.AvatarImage,
                g.Key.ChineseName,
                g.Key.EnglishName,
                g.Key.TitleCoverImage,
                g.Key.SteamAppId
            }).TakePage(page, 8).ToListAsync();

            var result = new SimilarPointList();

            foreach (var p in queryResult)
            {
                result.Add(new PointBasicInfo
                {
                    Id              = p.Id,
                    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)
                });
            }
            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);
        }