Exemplo n.º 1
0
        /// <summary>
        /// 创建 <see cref="DossierPage"/>
        /// </summary>
        /// <param name="user">用户对象</param>
        /// <param name="currentUserId">当前登录用户 ID</param>
        /// <param name="dbContext"><see cref="KeylolDbContext"/></param>
        /// <param name="cachedData"><see cref="CachedDataProvider"/></param>
        /// <param name="userManager"><see cref="KeylolUserManager"/></param>
        /// <returns><see cref="DossierPage"/></returns>
        public static async Task <DossierPage> CreateAsync(KeylolUser user, string currentUserId,
                                                           KeylolDbContext dbContext, CachedDataProvider cachedData, KeylolUserManager userManager)
        {
            var subscribedPoints =
                await SubscribedPointList.CreateAsync(currentUserId, user.Id, 1, 3, true, dbContext, cachedData);

            var selectedArticles =
                await SelectedArticleList.CreateAsync(user.Id, 1, 8, true, currentUserId, dbContext, cachedData);

            var dossierPage = new DossierPage
            {
                Coupon          = user.Coupon,
                LikeCount       = await cachedData.Likes.GetUserLikeCountAsync(user.Id),
                GameCount       = await dbContext.UserSteamGameRecords.CountAsync(r => r.UserId == user.Id),
                PlayedGameCount =
                    await dbContext.UserSteamGameRecords.CountAsync(r => r.UserId == user.Id && r.TotalPlayedTime > 0),
                SpotlightCount       = await dbContext.Articles.CountAsync(a => a.AuthorId == user.Id && a.Spotlighted),
                IsOperator           = await userManager.IsInRoleAsync(user.Id, KeylolRoles.Operator),
                SubscribedPointCount = subscribedPoints.Item2,
                SubscribedPoints     = subscribedPoints.Item1,
                ArticleCount         = selectedArticles.Item2,
                SelectedArticles     = selectedArticles.Item1
            };

            return(dossierPage);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建 <see cref="EditPage"/>
        /// </summary>
        /// <param name="user">用户对象</param>
        /// <param name="currentUserId">当前登录用户 ID</param>
        /// <param name="dbContext"><see cref="KeylolDbContext"/></param>
        /// <param name="userManager"><see cref="KeylolUserManager"/></param>
        /// <returns><see cref="EditPage"/></returns>
        public static async Task <EditPage> CreateAsync(KeylolUser user, string currentUserId, KeylolDbContext dbContext,
                                                        KeylolUserManager userManager)
        {
            if (currentUserId != user.Id && !await userManager.IsInRoleAsync(currentUserId, KeylolRoles.Operator))
            {
                return(new EditPage());
            }

            var editPage = new EditPage
            {
                Email                        = user.Email,
                LockoutEnabled               = user.LockoutEnabled,
                OpenInNewWindow              = user.OpenInNewWindow,
                UseEnglishPointName          = user.PreferredPointName == PreferredPointName.English,
                NotifyOnArticleReplied       = user.NotifyOnArticleReplied,
                NotifyOnCommentReplied       = user.NotifyOnCommentReplied,
                NotifyOnActivityReplied      = user.NotifyOnActivityReplied,
                NotifyOnArticleLiked         = user.NotifyOnArticleLiked,
                NotifyOnCommentLiked         = user.NotifyOnCommentLiked,
                NotifyOnActivityLiked        = user.NotifyOnActivityLiked,
                NotifyOnSubscribed           = user.NotifyOnSubscribed,
                SteamNotifyOnArticleReplied  = user.SteamNotifyOnArticleReplied,
                SteamNotifyOnCommentReplied  = user.SteamNotifyOnCommentReplied,
                SteamNotifyOnActivityReplied = user.SteamNotifyOnActivityReplied,
                SteamNotifyOnArticleLiked    = user.SteamNotifyOnArticleLiked,
                SteamNotifyOnCommentLiked    = user.SteamNotifyOnCommentLiked,
                SteamNotifyOnActivityLiked   = user.SteamNotifyOnActivityLiked,
                SteamNotifyOnSubscribed      = user.SteamNotifyOnSubscribed,
                SteamNotifyOnSpotlighted     = user.SteamNotifyOnSpotlighted,
                SteamNotifyOnMissive         = user.SteamNotifyOnMissive
            };

            if (user.SteamBotId == null)
            {
                editPage.SteamBotLost    = true;
                editPage.SteamBotSteamId = (await SteamBindingHub.GetNextBotAsync(dbContext)).SteamId;
            }
            else
            {
                editPage.SteamBotName    = $"其乐机器人 Keylol.com #{user.SteamBot.Sid}";
                editPage.SteamBotSteamId = user.SteamBot.SteamId;
            }
            return(editPage);
        }