コード例 #1
0
        public async Task <ActionResult> Home(int?id, int?aPageIndex, int?cPageIndex)
        {
            //个人主页
            if (!id.HasValue)
            {
                return(RedirectToAction("UserCenter"));
            }

            if (!aPageIndex.HasValue || aPageIndex.Value < 1)
            {
                aPageIndex = 1;
            }
            if (!cPageIndex.HasValue || cPageIndex.Value < 1)
            {
                cPageIndex = 1;
            }
            var entity = new HomeEntity();

            entity.User = Users.GetUserById(id.Value);
            if (entity.User == null || entity.User.IsNull)
            {
                return(new RedirectResult(Url.Action("Tip404", "Tips")));
            }
            entity.UserOther = await Users.GetUserOtherById(id.Value);

            entity.Positions = await Users.GetUserPositionById(entity.User.Id);

            entity.Articles = (await Articles.SearchArticlesByUserId(id.Value, 1, aPageIndex.Value, PageConfig.UserHomeArticlePageSize)).ToPagedList(aPageIndex.Value, PageConfig.UserHomeArticlePageSize);
            entity.Articles.TotalItemCount = await Articles.SearchArticlesCountByUserId(id.Value, 1);

            entity.Articles.CurrentPageIndex = aPageIndex.Value;

            entity.Comments = (await Comments.SearchCommentsByUserId(id.Value, 1, cPageIndex.Value, PageConfig.UserHomeCommentPageSize)).ToPagedList(cPageIndex.Value, PageConfig.UserHomeCommentPageSize);
            entity.Comments.TotalItemCount = await Comments.SearchCommentsCountByUserId(id.Value, 1);

            entity.Comments.CurrentPageIndex = cPageIndex.Value;
            return(View(entity));
        }