Ejemplo n.º 1
0
        /// <summary>
        /// 创建 <see cref="DiscoveryPage"/>
        /// </summary>
        /// <param name="currentUserId">当前登录用户 ID</param>
        /// <param name="dbContext"><see cref="KeylolDbContext"/></param>
        /// <param name="cachedData"><see cref="CachedDataProvider"/></param>
        /// <returns><see cref="DiscoveryPage"/></returns>
        public static async Task <DiscoveryPage> CreateAsync(string currentUserId, KeylolDbContext dbContext,
                                                             CachedDataProvider cachedData)
        {
            var onSalePoints = await OnSalePointList.CreateAsync(currentUserId, 1, true, true, dbContext, cachedData);

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

            return(new DiscoveryPage
            {
                SlideshowEntries = await SlideshowEntryList.CreateAsync(1, 4, dbContext),
                SpotlightPoints = await SpotlightPointList.CreateAsync(currentUserId, 1, 30, dbContext, cachedData),
                SpotlightReviews = await SpotlightArticleList.CreateAsync(currentUserId, 1, 4,
                                                                          SpotlightArticleStream.ArticleCategory.Review, dbContext, cachedData),
                SpotlightStudies = await SpotlightArticleList.CreateAsync(currentUserId, 1, 4,
                                                                          SpotlightArticleStream.ArticleCategory.Study, dbContext, cachedData),
                OnSalePointHeaderImage = onSalePoints.Item3,
                OnSalePointPageCount = onSalePoints.Item2,
                OnSalePoints = onSalePoints.Item1,
                SpotlightStories = await SpotlightArticleList.CreateAsync(currentUserId, 1, 4,
                                                                          SpotlightArticleStream.ArticleCategory.Story, dbContext, cachedData),
                LatestArticleHeaderImage = latestArticles.Item3,
                LatestArticlePageCount = latestArticles.Item2,
                LatestArticles = latestArticles.Item1,
                LatestActivityHeaderImage = onSalePoints.Item4,
                LatestActivities = await TimelineCardList.CreateAsync(LatestActivityStream.Name, currentUserId,
                                                                      12, false, dbContext, cachedData)
            });
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 获取精选谈论
 /// </summary>
 /// <param name="page">分页页码</param>
 /// <param name="dbContext"><see cref="KeylolDbContext"/></param>
 /// <param name="cachedData"><see cref="CachedDataProvider"/></param>
 /// <returns><see cref="SpotlightArticleList"/></returns>
 public static async Task <SpotlightArticleList> GetSpotlightStories(int page,
                                                                     [Injected] KeylolDbContext dbContext, [Injected] CachedDataProvider cachedData)
 {
     return(await SpotlightArticleList.CreateAsync(StateTreeHelper.GetCurrentUserId(), page, 12,
                                                   SpotlightArticleStream.ArticleCategory.Story, dbContext, cachedData));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建 <see cref="SpotlightArticleList"/>
        /// </summary>
        /// <param name="currentUserId">当前登录用户 ID</param>
        /// <param name="page">分页页码</param>
        /// <param name="recordsPerPage">每页数量</param>
        /// <param name="spotlightArticleCategory">文章分类</param>
        /// <param name="dbContext"><see cref="KeylolDbContext"/></param>
        /// <param name="cachedData"><see cref="CachedDataProvider"/></param>
        /// <returns><see cref="SpotlightArticleList"/></returns>
        public static async Task <SpotlightArticleList> CreateAsync(string currentUserId, int page, int recordsPerPage,
                                                                    SpotlightArticleStream.ArticleCategory spotlightArticleCategory, KeylolDbContext dbContext,
                                                                    CachedDataProvider cachedData)
        {
            var streamName  = SpotlightArticleStream.Name(spotlightArticleCategory);
            var queryResult = await(from feed in dbContext.Feeds
                                    where feed.StreamName == streamName
                                    join article in dbContext.Articles on feed.Entry equals article.Id
                                    where article.Rejected == false && article.Archived == ArchivedState.None
                                    orderby feed.Id descending
                                    select new
            {
                article.Id,
                FeedId         = feed.Id,
                FeedProperties = feed.Properties,
                article.AuthorId,
                AuthorIdCode      = article.Author.IdCode,
                AuthorAvatarImage = article.Author.AvatarImage,
                AuthorUserName    = article.Author.UserName,
                article.PublishTime,
                article.SidForAuthor,
                article.Title,
                article.Subtitle,
                article.CoverImage,
                PointIdCode      = article.TargetPoint.IdCode,
                PointAvatarImage = article.TargetPoint.AvatarImage,
                PointType        = article.TargetPoint.Type,
                PointChineseName = article.TargetPoint.ChineseName,
                PointEnglishName = article.TargetPoint.EnglishName,
                PointSteamAppId  = article.TargetPoint.SteamAppId
            })
                              .TakePage(page, recordsPerPage)
                              .ToListAsync();
            var result = new SpotlightArticleList(queryResult.Count);

            foreach (var a in queryResult)
            {
                var p = JsonConvert.DeserializeObject <SpotlightArticleStream.FeedProperties>(a.FeedProperties);
                result.Add(new SpotlightArticle
                {
                    Id                = a.Id,
                    FeedId            = a.FeedId,
                    AuthorIdCode      = a.AuthorIdCode,
                    AuthorAvatarImage = a.AuthorAvatarImage,
                    AuthorUserName    = a.AuthorUserName,
                    AuthorIsFriend    = string.IsNullOrWhiteSpace(currentUserId)
                        ? (bool?)null
                        : await cachedData.Users.IsFriendAsync(currentUserId, a.AuthorId),
                    PublishTime      = a.PublishTime,
                    SidForAuthor     = a.SidForAuthor,
                    Title            = p?.Title ?? a.Title,
                    Subtitle         = p?.Subtitle ?? a.Subtitle,
                    CoverImage       = a.CoverImage,
                    PointIdCode      = a.PointIdCode,
                    PointAvatarImage = a.PointAvatarImage,
                    PointType        = a.PointType,
                    PointChineseName = a.PointChineseName,
                    PointEnglishName = a.PointEnglishName,
                    PointInLibrary   = string.IsNullOrWhiteSpace(currentUserId) || a.PointSteamAppId == null
                        ? (bool?)null
                        : await cachedData.Users.IsSteamAppInLibraryAsync(currentUserId, a.PointSteamAppId.Value)
                });
            }
            return(result);
        }