/// <summary>
        /// 创建 <see cref="GenrePointList"/>
        /// </summary>
        /// <param name="pointId">据点 ID</param>
        /// <param name="currentUserId">当前登录用户 ID</param>
        /// <param name="dbContext"><see cref="KeylolDbContext"/></param>
        /// <param name="cachedData"><see cref="CachedDataProvider"/></param>
        /// <returns><see cref="GenrePointList"/></returns>
        public static async Task <GenrePointList> CreateAsync(string pointId, string currentUserId,
                                                              KeylolDbContext dbContext, CachedDataProvider cachedData)
        {
            var queryResult = await(from relationship in dbContext.PointRelationships
                                    where relationship.SourcePointId == pointId && relationship.Relationship == PointRelationshipType.Genre
                                    select new
            {
                relationship.TargetPoint.Id,
                relationship.TargetPoint.IdCode,
                relationship.TargetPoint.AvatarImage,
                relationship.TargetPoint.ChineseName,
                relationship.TargetPoint.EnglishName,
                GameCount = dbContext.PointRelationships
                            .Where(r => r.TargetPointId == relationship.TargetPointId)
                            .GroupBy(r => r.SourcePointId)
                            .Count()
            }).ToListAsync();

            var result = new GenrePointList(queryResult.Count);

            foreach (var p in queryResult)
            {
                result.Add(new GenrePoint
                {
                    Id          = p.Id,
                    IdCode      = p.IdCode,
                    AvatarImage = p.AvatarImage,
                    ChineseName = p.ChineseName,
                    EnglishName = p.EnglishName,
                    GameCount   = p.GameCount,
                    Subscribed  = string.IsNullOrWhiteSpace(currentUserId)
                        ? (bool?)null
                        : await cachedData.Subscriptions.IsSubscribedAsync(currentUserId, p.Id,
                                                                           SubscriptionTargetType.Point)
                });
            }
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// 创建 <see cref="IntelPage"/>
        /// </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="IntelPage"/></returns>
        public static async Task <IntelPage> CreateAsync(Models.Point point, string currentUserId,
                                                         KeylolDbContext dbContext, CachedDataProvider cachedData)
        {
            var intelPage = new IntelPage();

            if (point.Type == PointType.Game || point.Type == PointType.Hardware)
            {
                var vendorPointsGroup = await(from relationship in dbContext.PointRelationships
                                              where relationship.SourcePointId == point.Id &&
                                              (relationship.Relationship == PointRelationshipType.Developer ||
                                               relationship.Relationship == PointRelationshipType.Manufacturer ||
                                               relationship.Relationship == PointRelationshipType.Publisher ||
                                               relationship.Relationship == PointRelationshipType.Reseller)
                                              group relationship.Relationship by new
                {
                    relationship.TargetPoint.Id,
                    relationship.TargetPoint.IdCode,
                    relationship.TargetPoint.AvatarImage,
                    relationship.TargetPoint.ChineseName,
                    relationship.TargetPoint.EnglishName
                })
                                        .ToListAsync();
                intelPage.VendorPoints = vendorPointsGroup.Select(g => new VendorPoint
                {
                    IdCode      = g.Key.IdCode,
                    AvatarImage = g.Key.AvatarImage,
                    ChineseName = g.Key.ChineseName,
                    EnglishName = g.Key.EnglishName,
                    Roles       = string.Join("、", g.Select(r =>
                    {
                        switch (r)
                        {
                        case PointRelationshipType.Developer:
                            return("开发厂");

                        case PointRelationshipType.Publisher:
                            return("发行商");

                        case PointRelationshipType.Manufacturer:
                            return("制造厂");

                        case PointRelationshipType.Reseller:
                            return("代理商");

                        default:
                            return(r.ToString());
                        }
                    }))
                }).ToList();
                var vendorIds = vendorPointsGroup.Select(g => g.Key.Id).ToList();
                var vendorPointStaffQueryResult = await(from staff in dbContext.PointStaff
                                                        where vendorIds.Contains(staff.PointId)
                                                        select new
                {
                    staff.Staff.Id,
                    staff.Staff.HeaderImage,
                    staff.Staff.IdCode,
                    staff.Staff.AvatarImage,
                    staff.Staff.UserName,
                    PointChineseName = staff.Point.ChineseName,
                    PointEnglishName = staff.Point.EnglishName
                }).ToListAsync();
                intelPage.VenderPointStaff = new List <VendorPointStaff>(vendorPointStaffQueryResult.Count);
                foreach (var u in vendorPointStaffQueryResult)
                {
                    intelPage.VenderPointStaff.Add(new VendorPointStaff
                    {
                        Id               = u.Id,
                        HeaderImage      = u.HeaderImage,
                        IdCode           = u.IdCode,
                        AvatarImage      = u.AvatarImage,
                        UserName         = u.UserName,
                        PointChineseName = u.PointChineseName,
                        PointEnglishName = u.PointEnglishName,
                        IsFriend         = string.IsNullOrWhiteSpace(currentUserId)
                            ? (bool?)null
                            : await cachedData.Users.IsFriendAsync(currentUserId, u.Id),
                        Subscribed = string.IsNullOrWhiteSpace(currentUserId)
                            ? (bool?)null
                            : await cachedData.Subscriptions.IsSubscribedAsync(currentUserId, u.Id,
                                                                               SubscriptionTargetType.User)
                    });
                }
                intelPage.PointStaff = await PointStaffList.CreateAsync(point.Id, currentUserId, dbContext, cachedData);

                intelPage.GenrePoints = await GenrePointList.CreateAsync(point.Id, currentUserId, dbContext, cachedData);

                intelPage.TagPoints = await TagPointList.CreateAsync(point.Id, currentUserId, dbContext, cachedData);
            }
            if (point.Type == PointType.Game)
            {
                intelPage.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 特性属性

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

                #endregion

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

                SteamCrawlerProvider.UpdateSteamSpyData(point.Id);

                intelPage.PublishDate     = point.PublishDate;
                intelPage.PointCreateTime = point.CreateTime;
                intelPage.PreOrderDate    = point.PreOrderDate;
                intelPage.ReleaseDate     = point.ReleaseDate;

                if (point.SteamAppId != null)
                {
                    intelPage.OwnerCount                 = point.OwnerCount;
                    intelPage.OwnerCountVariance         = point.OwnerCountVariance;
                    intelPage.TotalPlayerCount           = point.TotalPlayerCount;
                    intelPage.TotalPlayerCountVariance   = point.TotalPlayerCountVariance;
                    intelPage.TwoWeekPlayerCount         = point.TwoWeekPlayerCount;
                    intelPage.TwoWeekPlayerCountVariance = point.TwoWeekPlayerCountVariance;
                    intelPage.Ccu = point.Ccu;
                    intelPage.AveragePlayedTime        = point.AveragePlayedTime;
                    intelPage.TwoWeekAveragePlayedTime = point.TwoWeekAveragePlayedTime;
                    intelPage.MedianPlayedTime         = point.MedianPlayedTime;
                }
            }
            return(intelPage);
        }