|
@@ -74,7 +74,7 @@ namespace Masuit.MyBlogs.Core.Controllers
|
|
|
/// <param name="orderBy"></param>
|
|
|
/// <returns></returns>
|
|
|
[Route("p"), ResponseCache(Duration = 600, VaryByQueryKeys = new[] { "page", "size", "orderBy" }, VaryByHeader = "Cookie")]
|
|
|
- public ActionResult Post([Optional]OrderBy? orderBy, [Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")]int page = 1, [Range(1, int.MaxValue, ErrorMessage = "页大小必须大于0")]int size = 15)
|
|
|
+ public ActionResult Post([Optional]OrderBy? orderBy, [Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")]int page = 1, [Range(1, 50, ErrorMessage = "页大小必须在0到50之间")]int size = 15)
|
|
|
{
|
|
|
var viewModel = GetIndexPageViewModel();
|
|
|
var postsQuery = PostService.GetQuery<PostDto>(p => (p.Status == Status.Pended || CurrentUser.IsAdmin)); //准备文章的查询
|
|
@@ -85,7 +85,7 @@ namespace Masuit.MyBlogs.Core.Controllers
|
|
|
}
|
|
|
|
|
|
viewModel.Posts = posts;
|
|
|
- viewModel.PageParams = new Pagination(1, 15, posts.TotalCount, OrderBy.ModifyDate);
|
|
|
+ viewModel.PageParams = new Pagination(page, size, posts.TotalCount, OrderBy.ModifyDate);
|
|
|
return View(viewModel);
|
|
|
}
|
|
|
|
|
@@ -98,13 +98,13 @@ namespace Masuit.MyBlogs.Core.Controllers
|
|
|
/// <param name="orderBy"></param>
|
|
|
/// <returns></returns>
|
|
|
[Route("tag/{id}/{page:int?}/{size:int?}/{orderBy:int?}"), ResponseCache(Duration = 600, VaryByQueryKeys = new[] { "id", "page", "size", "orderBy" }, VaryByHeader = "Cookie")]
|
|
|
- public ActionResult Tag(string id, [Optional]OrderBy? orderBy, [Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")]int page = 1, [Range(1, int.MaxValue, ErrorMessage = "页大小必须大于0")]int size = 15)
|
|
|
+ public ActionResult Tag(string id, [Optional]OrderBy? orderBy, [Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")]int page = 1, [Range(1, 50, ErrorMessage = "页大小必须在0到50之间")]int size = 15)
|
|
|
{
|
|
|
var posts = PostService.GetQuery<PostDto>(p => p.Label.Contains(id) && (p.Status == Status.Pended || CurrentUser.IsAdmin)).OrderBy($"{nameof(PostDto.IsFixedTop)} desc,{(orderBy ?? OrderBy.ModifyDate).GetDisplay()} desc").ToCachedPagedList(page, size);
|
|
|
var viewModel = GetIndexPageViewModel();
|
|
|
ViewBag.Tag = id;
|
|
|
viewModel.Posts = posts;
|
|
|
- viewModel.PageParams = new Pagination(1, 15, posts.TotalCount, OrderBy.ModifyDate);
|
|
|
+ viewModel.PageParams = new Pagination(page, size, posts.TotalCount, OrderBy.ModifyDate);
|
|
|
return View(viewModel);
|
|
|
}
|
|
|
|
|
@@ -117,7 +117,7 @@ namespace Masuit.MyBlogs.Core.Controllers
|
|
|
/// <param name="orderBy"></param>
|
|
|
/// <returns></returns>
|
|
|
[Route("author/{author}/{page:int?}/{size:int?}/{orderBy:int?}"), ResponseCache(Duration = 600, VaryByQueryKeys = new[] { "author", "page", "size", "orderBy" }, VaryByHeader = "Cookie")]
|
|
|
- public ActionResult Author(string author, [Optional]OrderBy? orderBy, [Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")]int page = 1, [Range(1, int.MaxValue, ErrorMessage = "页大小必须大于0")]int size = 15)
|
|
|
+ public ActionResult Author(string author, [Optional]OrderBy? orderBy, [Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")]int page = 1, [Range(1, 50, ErrorMessage = "页大小必须在0到50之间")]int size = 15)
|
|
|
{
|
|
|
Expression<Func<Post, bool>> where = p => p.Author.Equals(author) || p.Modifier.Equals(author) || p.Email.Equals(author) || p.PostHistoryVersion.Any(v => v.Modifier.Equals(author) || v.ModifierEmail.Equals(author));
|
|
|
where = where.And(p => p.Status == Status.Pended || CurrentUser.IsAdmin);
|
|
@@ -125,7 +125,7 @@ namespace Masuit.MyBlogs.Core.Controllers
|
|
|
var viewModel = GetIndexPageViewModel();
|
|
|
ViewBag.Author = author;
|
|
|
viewModel.Posts = posts;
|
|
|
- viewModel.PageParams = new Pagination(1, 15, posts.TotalCount, OrderBy.ModifyDate);
|
|
|
+ viewModel.PageParams = new Pagination(page, size, posts.TotalCount, OrderBy.ModifyDate);
|
|
|
return View(viewModel);
|
|
|
}
|
|
|
|
|
@@ -139,14 +139,14 @@ namespace Masuit.MyBlogs.Core.Controllers
|
|
|
/// <returns></returns>
|
|
|
[Route("cat/{id:int}"), ResponseCache(Duration = 600, VaryByQueryKeys = new[] { "id", "page", "size", "orderBy" }, VaryByHeader = "Cookie")]
|
|
|
[Route("cat/{id:int}/{page:int?}/{size:int?}/{orderBy:int?}")]
|
|
|
- public async Task<ActionResult> Category(int id, [Optional]OrderBy? orderBy, [Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")]int page = 1, [Range(1, int.MaxValue, ErrorMessage = "页大小必须大于0")]int size = 15)
|
|
|
+ public async Task<ActionResult> Category(int id, [Optional]OrderBy? orderBy, [Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")]int page = 1, [Range(1, 50, ErrorMessage = "页大小必须在0到50之间")]int size = 15)
|
|
|
{
|
|
|
var cat = await CategoryService.GetByIdAsync(id) ?? throw new NotFoundException("文章分类未找到");
|
|
|
var posts = PostService.GetQuery<PostDto>(p => p.CategoryId == cat.Id && (p.Status == Status.Pended || CurrentUser.IsAdmin)).OrderBy($"{nameof(PostDto.IsFixedTop)} desc,{(orderBy ?? OrderBy.ModifyDate).GetDisplay()} desc").ToCachedPagedList(page, size);
|
|
|
var viewModel = GetIndexPageViewModel();
|
|
|
viewModel.Posts = posts;
|
|
|
ViewBag.Category = cat;
|
|
|
- viewModel.PageParams = new Pagination(1, 15, posts.TotalCount, OrderBy.ModifyDate);
|
|
|
+ viewModel.PageParams = new Pagination(page, size, posts.TotalCount, OrderBy.ModifyDate);
|
|
|
return View(viewModel);
|
|
|
}
|
|
|
|