Browse Source

代码重构

懒得勤快 6 years ago
parent
commit
21815872a4

+ 9 - 9
src/Masuit.MyBlogs.Core/Controllers/PostController.cs

@@ -105,9 +105,9 @@ namespace Masuit.MyBlogs.Core.Controllers
         [Route("{id:int}/history"), Route("{id:int}/history/{page:int}/{size:int}"), ResponseCache(Duration = 600, VaryByQueryKeys = new[] { "id", "page", "size" }, VaryByHeader = HeaderNames.Cookie)]
         public ActionResult History(int id, int page = 1, int size = 20)
         {
-            var post = PostService.GetFromCache(p => p.Id == id && (p.Status == Status.Pended || CurrentUser.IsAdmin)).Mapper<PostOutputDto>() ?? throw new NotFoundException("文章未找到");
+            var post = PostService.Get(p => p.Id == id && (p.Status == Status.Pended || CurrentUser.IsAdmin)).Mapper<PostOutputDto>() ?? throw new NotFoundException("文章未找到");
             ViewBag.Primary = post;
-            var list = PostHistoryVersionService.GetPagesFromCache(page, size, out int total, v => v.PostId == id, v => v.ModifyDate, false).ToList();
+            var list = PostHistoryVersionService.GetPages(page, size, out int total, v => v.PostId == id, v => v.ModifyDate, false).ToList();
             ViewBag.Total = total;
             ViewBag.PageCount = Math.Ceiling(total * 1.0 / size).ToInt32();
             return View(list);
@@ -122,9 +122,9 @@ namespace Masuit.MyBlogs.Core.Controllers
         [Route("{id:int}/history/{hid:int}"), ResponseCache(Duration = 600, VaryByQueryKeys = new[] { "id", "hid" }, VaryByHeader = HeaderNames.Cookie)]
         public ActionResult HistoryVersion(int id, int hid)
         {
-            var post = PostHistoryVersionService.GetFromCache(v => v.Id == hid) ?? throw new NotFoundException("文章未找到");
-            ViewBag.Next = PostHistoryVersionService.GetFromCache(p => p.PostId == id && p.ModifyDate > post.ModifyDate, p => p.ModifyDate);
-            ViewBag.Prev = PostHistoryVersionService.GetFromCache(p => p.PostId == id && p.ModifyDate < post.ModifyDate, p => p.ModifyDate, false);
+            var post = PostHistoryVersionService.Get(v => v.Id == hid) ?? throw new NotFoundException("文章未找到");
+            ViewBag.Next = PostHistoryVersionService.Get(p => p.PostId == id && p.ModifyDate > post.ModifyDate, p => p.ModifyDate);
+            ViewBag.Prev = PostHistoryVersionService.Get(p => p.PostId == id && p.ModifyDate < post.ModifyDate, p => p.ModifyDate, false);
             return CurrentUser.IsAdmin ? View("HistoryVersion_Admin", post) : View(post);
         }
 
@@ -138,9 +138,9 @@ namespace Masuit.MyBlogs.Core.Controllers
         [Route("{id:int}/history/{v1:int}-{v2:int}"), ResponseCache(Duration = 600, VaryByQueryKeys = new[] { "id", "v1", "v2" }, VaryByHeader = HeaderNames.Cookie)]
         public ActionResult CompareVersion(int id, int v1, int v2)
         {
-            var main = PostService.GetFromCache(p => p.Id == id && (p.Status == Status.Pended || CurrentUser.IsAdmin)).Mapper<PostHistoryVersion>() ?? throw new NotFoundException("文章未找到");
-            var left = v1 <= 0 ? main : PostHistoryVersionService.GetFromCache(v => v.Id == v1) ?? throw new NotFoundException("文章未找到");
-            var right = v2 <= 0 ? main : PostHistoryVersionService.GetFromCache(v => v.Id == v2) ?? throw new NotFoundException("文章未找到");
+            var main = PostService.Get(p => p.Id == id && (p.Status == Status.Pended || CurrentUser.IsAdmin)).Mapper<PostHistoryVersion>() ?? throw new NotFoundException("文章未找到");
+            var left = v1 <= 0 ? main : PostHistoryVersionService.Get(v => v.Id == v1) ?? throw new NotFoundException("文章未找到");
+            var right = v2 <= 0 ? main : PostHistoryVersionService.Get(v => v.Id == v2) ?? throw new NotFoundException("文章未找到");
             main.Id = id;
             var diff = new HtmlDiff.HtmlDiff(right.Content, left.Content);
             var diffOutput = diff.Build();
@@ -277,7 +277,7 @@ namespace Masuit.MyBlogs.Core.Controllers
         [Route("all"), ResponseCache(Duration = 600, VaryByHeader = HeaderNames.Cookie)]
         public ActionResult All()
         {
-            var tags = PostService.GetQuery(p => !string.IsNullOrEmpty(p.Label)).Select(p => p.Label).Cacheable().SelectMany(s => s.Split(',', ',')).OrderBy(s => s).ToList(); //tag
+            var tags = PostService.GetQuery(p => !string.IsNullOrEmpty(p.Label)).Select(p => p.Label).SelectMany(s => s.Split(',', ',')).OrderBy(s => s).Cacheable().ToList(); //tag
             ViewBag.tags = tags.GroupBy(t => t).OrderByDescending(g => g.Count()).ThenBy(g => g.Key);
             ViewBag.cats = CategoryService.GetAll(c => c.Post.Count, false).Select(c => new TagCloudViewModel
             {

+ 6 - 7
src/Masuit.MyBlogs.Core/Controllers/SeminarController.cs

@@ -1,5 +1,4 @@
-using EFSecondLevelCache.Core;
-using Masuit.MyBlogs.Core.Common;
+using Masuit.MyBlogs.Core.Common;
 using Masuit.MyBlogs.Core.Extensions;
 using Masuit.MyBlogs.Core.Infrastructure.Services.Interface;
 using Masuit.MyBlogs.Core.Models.DTO;
@@ -48,19 +47,19 @@ namespace Masuit.MyBlogs.Core.Controllers
             switch (orderBy)
             {
                 case OrderBy.CommentCount:
-                    posts = temp.ThenByDescending(p => p.Comment.Count).Skip(size * (page - 1)).Take(size).Cacheable().ToList();
+                    posts = temp.ThenByDescending(p => p.Comment.Count).Skip(size * (page - 1)).Take(size).ToList();
                     break;
                 case OrderBy.PostDate:
-                    posts = temp.ThenByDescending(p => p.PostDate).Skip(size * (page - 1)).Take(size).Cacheable().ToList();
+                    posts = temp.ThenByDescending(p => p.PostDate).Skip(size * (page - 1)).Take(size).ToList();
                     break;
                 case OrderBy.ViewCount:
-                    posts = temp.ThenByDescending(p => p.TotalViewCount).Skip(size * (page - 1)).Take(size).Cacheable().ToList();
+                    posts = temp.ThenByDescending(p => p.TotalViewCount).Skip(size * (page - 1)).Take(size).ToList();
                     break;
                 case OrderBy.VoteCount:
-                    posts = temp.ThenByDescending(p => p.VoteUpCount).Skip(size * (page - 1)).Take(size).Cacheable().ToList();
+                    posts = temp.ThenByDescending(p => p.VoteUpCount).Skip(size * (page - 1)).Take(size).ToList();
                     break;
                 default:
-                    posts = temp.ThenByDescending(p => p.ModifyDate).Skip(size * (page - 1)).Take(size).Cacheable().ToList();
+                    posts = temp.ThenByDescending(p => p.ModifyDate).Skip(size * (page - 1)).Take(size).ToList();
                     break;
             }
             ViewBag.Total = temp.Count();

+ 4 - 4
src/Masuit.MyBlogs.Core/Infrastructure/Repository/BaseRepository.cs

@@ -264,7 +264,7 @@ namespace Masuit.MyBlogs.Core.Infrastructure.Repository
         /// </summary>
         /// <param name="where">查询条件</param>
         /// <returns>实体</returns>
-        public T GetFromCache(Expression<Func<T, bool>> @where)
+        public virtual T GetFromCache(Expression<Func<T, bool>> @where)
         {
             return DataContext.Set<T>().Where(where).Cacheable().FirstOrDefault();
         }
@@ -290,7 +290,7 @@ namespace Masuit.MyBlogs.Core.Infrastructure.Repository
         /// <param name="orderby">排序字段</param>
         /// <param name="isAsc">是否升序</param>
         /// <returns>实体</returns>
-        public T GetFromCache<TS>(Expression<Func<T, bool>> @where, Expression<Func<T, TS>> @orderby, bool isAsc = true)
+        public virtual T GetFromCache<TS>(Expression<Func<T, bool>> @where, Expression<Func<T, TS>> @orderby, bool isAsc = true)
         {
             return isAsc ? DataContext.Set<T>().OrderBy(orderby).Where(where).Cacheable().FirstOrDefault() : DataContext.Set<T>().OrderByDescending(orderby).Where(where).Cacheable().FirstOrDefault();
         }
@@ -304,7 +304,7 @@ namespace Masuit.MyBlogs.Core.Infrastructure.Repository
         /// <param name="orderby">排序字段</param>
         /// <param name="isAsc">是否升序</param>
         /// <returns>映射实体</returns>
-        public TDto GetFromCache<TS, TDto>(Expression<Func<T, bool>> @where, Expression<Func<T, TS>> @orderby, bool isAsc = true) where TDto : class
+        public virtual TDto GetFromCache<TS, TDto>(Expression<Func<T, bool>> @where, Expression<Func<T, TS>> @orderby, bool isAsc = true) where TDto : class
         {
             return isAsc ? DataContext.Set<T>().Where(where).OrderBy(orderby).ProjectTo<TDto>(MapperConfig).Cacheable().FirstOrDefault() : DataContext.Set<T>().Where(where).OrderByDescending(orderby).ProjectTo<TDto>(MapperConfig).Cacheable().FirstOrDefault(); ;
         }
@@ -370,7 +370,7 @@ namespace Masuit.MyBlogs.Core.Infrastructure.Repository
         /// </summary>
         /// <param name="where">查询条件</param>
         /// <returns>实体</returns>
-        public TDto GetFromCache<TDto>(Expression<Func<T, bool>> @where) where TDto : class
+        public virtual TDto GetFromCache<TDto>(Expression<Func<T, bool>> @where) where TDto : class
         {
             return DataContext.Set<T>().Where(where).ProjectTo<TDto>(MapperConfig).Cacheable().FirstOrDefault();
         }

+ 1 - 1
src/Masuit.MyBlogs.Core/Infrastructure/Services/BaseService.cs

@@ -49,7 +49,7 @@ namespace Masuit.MyBlogs.Core.Infrastructure.Services
         /// 从二级缓存获取所有实体
         /// </summary>
         /// <returns>还未执行的SQL语句</returns>
-        public virtual EFCachedDbSet<T> GetAllFromCache()
+        public virtual IEnumerable<T> GetAllFromCache()
         {
             return BaseDal.GetAllFromCache();
         }

+ 1 - 1
src/Masuit.MyBlogs.Core/Infrastructure/Services/Interface/IBaseService.cs

@@ -25,7 +25,7 @@ namespace Masuit.MyBlogs.Core.Infrastructure.Services.Interface
         /// 从二级缓存获取所有实体
         /// </summary>
         /// <returns>还未执行的SQL语句</returns>
-        EFCachedDbSet<T> GetAllFromCache();
+        IEnumerable<T> GetAllFromCache();
 
         /// <summary>
         /// 获取所有实体

+ 0 - 13
src/Masuit.MyBlogs.Core/wwwroot/ng-views/controllers/post.js

@@ -25,19 +25,6 @@
 			self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
 		}
 	});
-	$('.field').dropdown({
-		allowAdditions: false,
-		onChange: function (value) {
-			var state = ["Author", "Email", "Status", "VoteUpCount", "VoteDownCount"];
-			state.map(function (item, index, array) {
-				$scope[item] = false;
-			});
-			value.split(",").map(function (item, index, array) {
-				$scope[item] = true;
-			});
-			self.tableParams.reload();
-		}
-	});
 	this.GetPageData = function (page, size) {
 		$scope.loading();
 		$http.post("/post/getpagedata", {

File diff suppressed because it is too large
+ 0 - 0
src/Masuit.MyBlogs.Core/wwwroot/ng-views/controllers/post.min.js


+ 7 - 7
src/Masuit.MyBlogs.Core/wwwroot/ng-views/views/post/pending.html

@@ -10,24 +10,24 @@
             </div>
         </div>
     </div>
-    <table ng-table="list.tableParams" class="table table-bordered table-hover table-condensed editable-table listTable" ng-form="list.tableForm" disable-filter="list.isAdding" tracked-table="list.tableTracker">
+    <table ng-table="list.tableParams" class="table table-bordered table-hover table-condensed listTable" ng-form="list.tableForm" tracked-table="list.tableTracker">
         <tr ng-repeat="row in $data" ng-form="rowForm" tracked-table-row="row">
-            <td title="'标题'" filter="{Title: 'text'}" sortable="'Title'">
+            <td title="'标题'">
                 <a href="/{{row.Id}}" target="_blank">{{row.Title}}</a>
             </td>
-            <td title="'作者'" filter="{Author: 'text'}" sortable="'Author'" ng-if="Author">
+            <td title="'作者'">
                 {{row.Author}}
             </td>
-            <td title="'发表'" filter="{PostDate: 'text'}" sortable="'PostDate'">
+            <td title="'发表'">
                 {{row.PostDate|date:'yyyy-MM-dd HH:mm:ss'}}
             </td>
-            <td title="'分类'" filter="{CategoryName: 'text'}" sortable="'CategoryName'">
+            <td title="'分类'">
                 {{row.CategoryName}}
             </td>
-            <td title="'作者邮箱'" filter="{Email: 'text'}" sortable="'Email'" ng-if="Email">
+            <td title="'作者邮箱'">
                 {{row.Email}}
             </td>
-            <td title="'标签'" filter="{Label: 'text'}" sortable="'Label'">
+            <td title="'标签'">
                 {{row.Label}}
             </td>
             <td title="'操作'" style="width: 155px;">

+ 7 - 25
src/Masuit.MyBlogs.Core/wwwroot/ng-views/views/post/postlist.html

@@ -30,30 +30,18 @@
                 </div>
             </div>
         </div>
-        <div class="input-group">
-            <span class="input-group-addon">显示字段:</span>
-            <div class="ui multiple search selection dropdown field">
-                <input type="hidden" id="field">
-                <i class="dropdown icon"></i>
-                <div class="default text">选择字段</div>
-                <div class="menu">
-                    <div class="item" data-value="Author">作者</div>
-                    <div class="item" data-value="Email">作者邮箱</div>
-                    <div class="item" data-value="VoteUpCount">支持数</div>
-                    <div class="item" data-value="VoteDownCount">反对数</div>
-                    <div class="item" data-value="Status">状态</div>
-                </div>
-            </div>
-        </div>
     </div>
-    <table ng-table="list.tableParams" class="table table-bordered table-hover table-condensed editable-table listTable" ng-form="list.tableForm" disable-filter="list.isAdding" tracked-table="list.tableTracker">
+    <table ng-table="list.tableParams" class="table table-bordered table-hover table-condensed listTable" ng-form="list.tableForm" tracked-table="list.tableTracker">
         <tr ng-repeat="row in $data" ng-form="rowForm" tracked-table-row="row">
             <td title="'标题'">
                 <a ng-href="/{{row.Id}}" target="_blank">{{row.Title}}</a>
             </td>
-            <td title="'作者'" ng-if="Author">
+            <td title="'作者'">
                 {{row.Author}}
             </td>
+            <td title="'作者邮箱'">
+                {{row.Email}}
+            </td>
             <td title="'阅读'">
                 {{row.ViewCount}}
             </td>
@@ -69,19 +57,13 @@
             <td title="'分类'">
                 {{row.CategoryName}}
             </td>
-            <td title="'作者邮箱'" ng-if="Email">
-                {{row.Email}}
-            </td>
             <td title="'标签'">
                 {{row.Label}}
             </td>
-            <td title="'支持'" ng-if="VoteUpCount">
+            <td title="'支持'">
                 {{row.VoteUpCount}}
             </td>
-            <td title="'反对'" ng-if="VoteDownCount">
-                {{row.VoteDownCount}}
-            </td>
-            <td title="'状态'" ng-if="Status">
+            <td title="'状态'">
                 {{row.Status}}
             </td>
             <td title="'禁止评论'">

Some files were not shown because too many files changed in this diff