public async Task <ActionResult> ArticleList_two(int pageIndex = 1, int pageSize = 2) { var articleMgr = new ArticleManager(); var userid = Guid.Parse(Session["userid"].ToString()); //当前用户第n页数据 var articles = await articleMgr.GetAllArticlesByUserId(userid, pageIndex - 1, pageSize); var dataCount = await articleMgr.GetDataCount(userid); return(View(new PagedList <Dto.ArticleDto>(articles, pageIndex, pageSize, dataCount))); }
public async Task <ActionResult> AritcleList(int pageIndex = 0, int pageSize = 1) { //需要给页面前端 总页码数,当前页码,可显示的总页码数量 var articleMgr = new ArticleManager(); var userid = Guid.Parse(Session["userid"].ToString()); var articles = await articleMgr.GetAllArticlesByUserId(userid, pageIndex, pageSize); var dataCount = await articleMgr.GetDataCount(userid); ViewBag.PageCount = dataCount % pageSize == 0 ? dataCount / pageSize : dataCount / pageSize + 1; ViewBag.PageIndex = pageIndex; return(View(articles)); }
public async Task <ActionResult> ArticleList(int pageIndex = 1, int pageSize = 3) { // 需要给页面前端总页码数,当前页码,可显示的总页码数量 var manager = new ArticleManager(); var userid = Guid.Parse(Session["userid"].ToString()); // 当前用户第n页数据 var articles = await manager.GetAllArticlesByUserId(userid, pageIndex - 1, pageSize); // 获取当前用户文章总数 var dataCount = await manager.GetDataCount(userid); //ViewBag.PageCount = dataCount % pageSize == 0 ? dataCount / pageSize : dataCount / pageSize + 1; //ViewBag.PageIndex = pageIndex; return(View(new PagedList <ArticleDto>(articles, pageIndex, pageSize, dataCount))); }
public static int flag = 0;//是否删除标记 protected void GetAll() { sigma = ArticleManager.GetAllArticlesByUserId(Now_User.now_user_id); }
public async Task <ActionResult> GetArticleList(string userId, string categoryId = null, int pageIndex = 1, int pageSize = 7) { //获取当前登陆的id,cookie的id需要解密 string userCookieId = ""; string message; if (Request.Cookies["userId"] != null) { if (!JwtHelper.GetJwtDecode(Request.Cookies["userId"].Value, out userCookieId, out message)) { return(Json(new { result = message, status = "fail" }, JsonRequestBehavior.AllowGet));//返回错误信息 } } string currentUserId = Session["userId"] == null ? userCookieId : Session["userId"].ToString(); if (userId == null && currentUserId != null && currentUserId.Trim() != "") { return(RedirectToAction(nameof(GetArticleList), new { userId = currentUserId })); } //需要返回前端 总页数 当前页数 单个页面数量 IArticleManager articleManager = new ArticleManager(); IUserManager userManager = new UserManager(); Guid userIdGuid; Guid.TryParse(userId, out userIdGuid); if (!await userManager.ExistsUser(userIdGuid) || userIdGuid == Guid.Empty) { return(Json(new { result = "未能找到对应ID的用户,请稍后再试", status = "fail" }, JsonRequestBehavior.AllowGet));//返回错误信息 } //新增按照用户id和分类id查找文章,默认为不找分类id Guid categoryIdGuid; Guid.TryParse(categoryId, out categoryIdGuid); List <ArticleDto> articlesInfo; int dataCount; if (categoryIdGuid == Guid.Empty) { articlesInfo = await articleManager.GetAllArticlesByUserId(userIdGuid, (pageIndex - 1), pageSize); //数据库是从0开始的 dataCount = await articleManager.GetArticleDataCount(userIdGuid); //文章总数 } else { articlesInfo = await articleManager.GetAllArticlesByUserIdAndCategoryId(userIdGuid, categoryIdGuid, (pageIndex - 1), pageSize); //数据库是从0开始的 dataCount = await articleManager.GetArticleDataCount(userIdGuid, categoryIdGuid); //文章总数 } var pageCount = dataCount % pageSize == 0 ? dataCount / pageSize : dataCount / pageSize + 1; //总页数 var category = categoryIdGuid == Guid.Empty ? null : await articleManager.GetOneCategoryById(categoryIdGuid); var isCurrentUser = currentUserId.Trim() == "" ? false : userIdGuid == Guid.Parse(currentUserId) ? true : false; //是否为当前登陆用户 var requestId = userIdGuid; //当前请求id var tenTags = await articleManager.GetCategoriesByCount(userIdGuid, 10); //返回10个分类 var articlesCount = await articleManager.GetArticleDataCount(userIdGuid); //查找文章总数 var categoriesCount = await articleManager.GetCategoryDataCount(userIdGuid); //查找分类总数 var isFocused = currentUserId.Trim() == "" ? false : await userManager.IsFocused(Guid.Parse(currentUserId), userIdGuid); //id为空也视为没关注 var userInfo = await userManager.GetUserById(userIdGuid); var pageMatchArticleCount = dataCount; return(Json(new { status = "ok", articlesInfo, pageMatchArticleCount, pageCount, pageIndex, pageSize, category, isCurrentUser, requestId, tenTags, articlesCount, categoriesCount, isFocused, userInfo }, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> ArticleList(string userId, string categoryId = null, int pageIndex = 1, int pageSize = 7) { //获取当前登陆的id,cookie的id需要解密 string userCookieId = ""; string message; if (Request.Cookies["userId"] != null) { if (!JwtHelper.GetJwtDecode(Request.Cookies["userId"].Value, out userCookieId, out message)) { ErrorController.message = message; return(RedirectToAction("IllegalOperationError", "Error"));//返回错误页面 } } string currentUserId = Session["userId"] == null ? userCookieId : Session["userId"].ToString(); if (userId == null && currentUserId != null && currentUserId.Trim() != "") { return(RedirectToAction(nameof(ArticleList), new { userId = currentUserId })); } //需要返回前端 总页数 当前页数 单个页面数量 IArticleManager articleManager = new ArticleManager(); IUserManager userManager = new UserManager(); Guid userIdGuid; Guid.TryParse(userId, out userIdGuid); if (!await userManager.ExistsUser(userIdGuid) || userIdGuid == Guid.Empty) { ErrorController.message = "未能找到对应ID的用户,请稍后再试"; return(RedirectToAction("IllegalOperationError", "Error"));//返回错误页面 } //新增按照用户id和分类id查找文章,默认为不找分类id Guid categoryIdGuid; Guid.TryParse(categoryId, out categoryIdGuid); List <ArticleDto> articles; int dataCount; if (categoryIdGuid == Guid.Empty) { articles = await articleManager.GetAllArticlesByUserId(userIdGuid, (pageIndex - 1), pageSize); //数据库是从0开始的 dataCount = await articleManager.GetArticleDataCount(userIdGuid); //文章总数 } else { articles = await articleManager.GetAllArticlesByUserIdAndCategoryId(userIdGuid, categoryIdGuid, (pageIndex - 1), pageSize); //数据库是从0开始的 dataCount = await articleManager.GetArticleDataCount(userIdGuid, categoryIdGuid); //文章总数 } ViewBag.PageCount = dataCount % pageSize == 0 ? dataCount / pageSize : dataCount / pageSize + 1; //总页数 ViewBag.PageIndex = pageIndex; //当前页数 ViewBag.PageSize = pageSize; //当前显示数目 ViewBag.Category = categoryIdGuid == Guid.Empty ? null : await articleManager.GetOneCategoryById(categoryIdGuid); ViewBag.IsCurrentUser = currentUserId.Trim() == "" ? false : userIdGuid == Guid.Parse(currentUserId) ? true : false; //是否为当前登陆用户 ViewBag.RequestId = userIdGuid; //当前请求id ViewBag.TenTags = await articleManager.GetCategoriesByCount(userIdGuid, 10); //返回10个分类 ViewBag.ArticlesCount = await articleManager.GetArticleDataCount(userIdGuid); //查找文章总数 ViewBag.CategoriesCount = await articleManager.GetCategoryDataCount(userIdGuid); //查找分类总数 ViewBag.IsFocused = currentUserId.Trim() == "" ? false : await userManager.IsFocused(Guid.Parse(currentUserId), userIdGuid); //id为空也视为没关注 ViewBag.User = await userManager.GetUserById(userIdGuid); return(View(articles)); }