1
0
懒得勤快 6 жил өмнө
parent
commit
168b4d2f76

+ 45 - 0
src/Masuit.MyBlogs.Core/Controllers/HomeController.cs

@@ -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>

+ 10 - 0
src/Masuit.MyBlogs.Core/Masuit.MyBlogs.Core.xml

@@ -750,6 +750,16 @@
             <param name="orderBy"></param>
             <returns></returns>
         </member>
+        <member name="M:Masuit.MyBlogs.Core.Controllers.HomeController.Author(System.String,System.Nullable{Masuit.MyBlogs.Core.Models.Enum.OrderBy},System.Int32,System.Int32)">
+            <summary>
+            作者文章页
+            </summary>
+            <param name="id"></param>
+            <param name="page"></param>
+            <param name="size"></param>
+            <param name="orderBy"></param>
+            <returns></returns>
+        </member>
         <member name="M:Masuit.MyBlogs.Core.Controllers.HomeController.Category(System.Int32,System.Nullable{Masuit.MyBlogs.Core.Models.Enum.OrderBy},System.Int32,System.Int32)">
             <summary>
             分类文章页

+ 50 - 0
src/Masuit.MyBlogs.Core/Views/Home/Author.cshtml

@@ -0,0 +1,50 @@
+@using Masuit.MyBlogs.Core.Models.DTO
+@using Masuit.MyBlogs.Core.Models.ViewModel
+@using Masuit.Tools.Core.Net
+@model IndexPageViewModel
+@{
+    ViewBag.Title = "作者_" + ViewBag.Author;
+    Layout = "~/Views/Shared/_Layout.cshtml";
+    Random r = new Random();
+}
+<style>
+    .bg-title {
+        height: 50vh;
+        max-height: 400px;
+        position: relative;
+        background: url(/Content/images/@(r.Next(1,9)).jpg) no-repeat center;
+        background-size:cover;
+        background-attachment: fixed;
+        margin-bottom: 10px;
+    }
+    .header-content {
+        position: absolute;
+        left: 50%;
+        top: 50%;
+        transform: translate(-50%,-50%);
+    }
+    .header-content .divider {
+        width: inherit;
+        height: 20px;
+        margin-top: 20px;
+        border-top: 3px solid rebeccapurple;
+    }
+</style>
+<div class="container">
+    <ol class="cd-breadcrumb triangle">
+        <li>@Html.ActionLink("首页", "Index", "Home")</li>
+        <li class="current"><em>@ViewBag.Title</em></li>
+    </ol>
+</div>
+<div class="bg-title">
+    <div class="header-content text-center">
+        <h1 class="size48">
+            @ViewBag.Author 参与编辑的文章
+        </h1>
+        <div class="divider"></div>
+    </div>
+</div>
+@{
+    var user = Context.Session.Get<UserInfoOutputDto>(SessionKey.UserInfo) ?? new UserInfoOutputDto();
+    await Html.RenderPartialAsync(user.IsAdmin ? "_MainContainer_Admin" : "_MainContainer", Model);
+}

+ 1 - 2
src/Masuit.MyBlogs.Core/Views/Home/Category.cshtml

@@ -1,5 +1,4 @@
-@using Masuit.MyBlogs.Core.Extensions
-@using Masuit.MyBlogs.Core.Models.DTO
+@using Masuit.MyBlogs.Core.Models.DTO
 @using Masuit.MyBlogs.Core.Models.ViewModel
 @using Masuit.Tools.Core.Net
 @model Masuit.MyBlogs.Core.Models.ViewModel.IndexPageViewModel

+ 6 - 2
src/Masuit.MyBlogs.Core/Views/Post/Details.cshtml

@@ -45,8 +45,12 @@
                             <div class="row">
                                 <div class="col-sm-8">
                                     <div class="padding-bot10">
-                                        <span class="label label-@colors[new Random().Next() % colors.Length]">@Model.Author</span>发表于<span class="text-info">@Model.PostDate.ToString("yyyy-MM-dd HH:mm:ss")</span> |
-                                        <span class="label label-@colors[new Random().Next() % colors.Length]">@Model.Modifier</span>最后修改于<span class="text-success">@Model.ModifyDate.ToString("yyyy-MM-dd HH:mm:ss")</span>
+                                        <span class="label label-@colors[new Random().Next() % colors.Length]">
+                                            <a asp-controller="Home" asp-action="Author" asp-route-author="@Model.Author">@Model.Author</a>
+                                        </span>发表于<span class="text-info">@Model.PostDate.ToString("yyyy-MM-dd HH:mm:ss")</span> |
+                                        <span class="label label-@colors[new Random().Next() % colors.Length]">
+                                            <a asp-controller="Home" asp-action="Author" asp-route-author="@Model.Modifier">@Model.Modifier</a>
+                                        </span>最后修改于<span class="text-success">@Model.ModifyDate.ToString("yyyy-MM-dd HH:mm:ss")</span>
                                     </div>
                                 </div>
                                 @{

+ 6 - 2
src/Masuit.MyBlogs.Core/Views/Post/Details_Admin.cshtml

@@ -55,8 +55,12 @@
                             <div class="row">
                                 <div class="col-sm-8">
                                     <div class="padding-bot10">
-                                        <span class="label label-@colors[new Random().Next() % colors.Length]">@Model.Author</span>发表于<span class="text-info">@Model.PostDate.ToString("yyyy-MM-dd HH:mm:ss")</span> |
-                                        <span class="label label-@colors[new Random().Next() % colors.Length]">@Model.Modifier</span>最后修改于<span class="text-success">@Model.ModifyDate.ToString("yyyy-MM-dd HH:mm:ss")</span>
+                                        <span class="label label-@colors[new Random().Next() % colors.Length]">
+                                            <a asp-controller="Home" asp-action="Author" asp-route-author="@Model.Author">@Model.Author</a>
+                                        </span>发表于<span class="text-info">@Model.PostDate.ToString("yyyy-MM-dd HH:mm:ss")</span> |
+                                        <span class="label label-@colors[new Random().Next() % colors.Length]">
+                                            <a asp-controller="Home" asp-action="Author" asp-route-author="@Model.Modifier">@Model.Modifier</a>
+                                        </span>最后修改于<span class="text-success">@Model.ModifyDate.ToString("yyyy-MM-dd HH:mm:ss")</span>
                                     </div>
                                 </div>
                                 @{

+ 3 - 1
src/Masuit.MyBlogs.Core/Views/Shared/_ArticleListItem.cshtml

@@ -32,7 +32,9 @@
             }
             <div class="col-md-@(string.IsNullOrEmpty(imgSrc) ? 12 : 9)">
                 <div class="small padding-bot10">
-                    作者:<i class="icon-user-check"></i><strong class="label label-primary">@Model.Author</strong> <span class="text-muted">
+                    作者:<i class="icon-user-check"></i><strong class="label label-primary">
+                        <a asp-controller="Home" asp-action="Author" asp-route-author="@Model.Author">@Model.Author</a>
+                    </strong> <span class="text-muted">
                         | 发表时间:<i class="fa fa-clock-o"></i> @Model.ModifyDate.ToString("yyyy-MM-dd HH:mm") | 分类:<i class="icon-map-pin"></i>@Html.ActionLink(Model.CategoryName, "Category", "Home", new { id = Model.CategoryId }, null)
                     </span>
                 </div>

+ 4 - 3
src/Masuit.MyBlogs.Core/Views/Shared/_ArticleListItem_Admin.cshtml

@@ -32,9 +32,10 @@
             }
             <div class="col-sm-@(string.IsNullOrEmpty(imgSrc) ? 12 : 9)">
                 <div class="small padding-bot10">
-                    作者:<i class="icon-user-check"></i><strong class="label label-primary">@Model.Author</strong> <span class="text-muted">
-                        |
-                        发表时间:<i class="fa fa-clock-o"></i> @Model.ModifyDate.ToString("yyyy-MM-dd HH:mm") |
+                    作者:<i class="icon-user-check"></i><strong class="label label-primary">
+                        <a asp-controller="Home" asp-action="Author" asp-route-author="@Model.Author">@Model.Author</a>
+                    </strong> <span class="text-muted">
+                        | 发表时间:<i class="fa fa-clock-o"></i> @Model.ModifyDate.ToString("yyyy-MM-dd HH:mm") |
                         分类:<i class="icon-map-pin"></i>@Html.ActionLink(Model.CategoryName, "Category", "Home", new { id = Model.CategoryId }, null)
                     </span>
                 </div>

+ 4 - 1
src/Masuit.MyBlogs.Core/wwwroot/Content/common/articlestyle.css

@@ -1,4 +1,7 @@
-.border {
+.label a {
+    color: white;
+}
+.border {
     border: #ccc 1px solid;
     border-radius: 5px;
     /*margin-bottom: 10px;*/