|
|
@@ -1,8 +1,10 @@
|
|
|
using AutoMapper.QueryableExtensions;
|
|
|
using EFSecondLevelCache.Core;
|
|
|
+using Masuit.LuceneEFCore.SearchEngine.Linq;
|
|
|
using Masuit.MyBlogs.Core.Extensions;
|
|
|
using Masuit.MyBlogs.Core.Infrastructure.Services.Interface;
|
|
|
using Masuit.MyBlogs.Core.Models.DTO;
|
|
|
+using Masuit.MyBlogs.Core.Models.Entity;
|
|
|
using Masuit.MyBlogs.Core.Models.Enum;
|
|
|
using Masuit.MyBlogs.Core.Models.ViewModel;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
@@ -113,6 +115,49 @@ namespace Masuit.MyBlogs.Core.Controllers
|
|
|
return View(viewModel);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 作者文章页
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <param name="page"></param>
|
|
|
+ /// <param name="size"></param>
|
|
|
+ /// <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)
|
|
|
+ {
|
|
|
+ IList<PostOutputDto> posts;
|
|
|
+ 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);
|
|
|
+ var temp = PostService.GetQuery<PostOutputDto>(where).OrderByDescending(p => p.IsFixedTop);
|
|
|
+ switch (orderBy)
|
|
|
+ {
|
|
|
+ case OrderBy.CommentCount:
|
|
|
+ posts = temp.ThenByDescending(p => p.CommentCount).Skip(size * (page - 1)).Take(size).Cacheable().ToList();
|
|
|
+ break;
|
|
|
+ case OrderBy.PostDate:
|
|
|
+ posts = temp.ThenByDescending(p => p.PostDate).Skip(size * (page - 1)).Take(size).Cacheable().ToList();
|
|
|
+ break;
|
|
|
+ case OrderBy.ViewCount:
|
|
|
+ posts = temp.ThenByDescending(p => p.TotalViewCount).Skip(size * (page - 1)).Take(size).Cacheable().ToList();
|
|
|
+ break;
|
|
|
+ case OrderBy.VoteCount:
|
|
|
+ posts = temp.ThenByDescending(p => p.VoteUpCount).Skip(size * (page - 1)).Take(size).Cacheable().ToList();
|
|
|
+ break;
|
|
|
+ case OrderBy.AverageViewCount:
|
|
|
+ posts = temp.ThenByDescending(p => p.AverageViewCount).Skip(size * (page - 1)).Take(size).Cacheable().ToList();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ posts = temp.ThenByDescending(p => p.ModifyDate).Skip(size * (page - 1)).Take(size).Cacheable().ToList();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ var viewModel = GetIndexPageViewModel(1, 1, orderBy, CurrentUser);
|
|
|
+ ViewBag.Total = temp.Count();
|
|
|
+ ViewBag.Author = author;
|
|
|
+ viewModel.Posts = posts;
|
|
|
+ return View(viewModel);
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 分类文章页
|
|
|
/// </summary>
|