Răsfoiți Sursa

部分代码重构

懒得勤快 5 ani în urmă
părinte
comite
1e70055ee1
25 a modificat fișierele cu 173 adăugiri și 188 ștergeri
  1. 2 2
      src/Masuit.MyBlogs.Core/Configs/MappingProfile.cs
  2. 1 1
      src/Masuit.MyBlogs.Core/Controllers/AdvertisementController.cs
  3. 2 1
      src/Masuit.MyBlogs.Core/Controllers/FileController.cs
  4. 1 1
      src/Masuit.MyBlogs.Core/Controllers/HomeController.cs
  5. 1 4
      src/Masuit.MyBlogs.Core/Controllers/LinksController.cs
  6. 2 2
      src/Masuit.MyBlogs.Core/Controllers/LoginController.cs
  7. 2 5
      src/Masuit.MyBlogs.Core/Controllers/MenuController.cs
  8. 1 6
      src/Masuit.MyBlogs.Core/Controllers/MergeController.cs
  9. 1 5
      src/Masuit.MyBlogs.Core/Controllers/MiscController.cs
  10. 2 2
      src/Masuit.MyBlogs.Core/Controllers/MsgController.cs
  11. 1 5
      src/Masuit.MyBlogs.Core/Controllers/NoticeController.cs
  12. 15 11
      src/Masuit.MyBlogs.Core/Controllers/PassportController.cs
  13. 12 18
      src/Masuit.MyBlogs.Core/Controllers/PostController.cs
  14. 7 6
      src/Masuit.MyBlogs.Core/Controllers/SearchController.cs
  15. 1 0
      src/Masuit.MyBlogs.Core/Controllers/SeminarController.cs
  16. 20 21
      src/Masuit.MyBlogs.Core/Controllers/SubscribeController.cs
  17. 9 4
      src/Masuit.MyBlogs.Core/Controllers/ToolsController.cs
  18. 23 28
      src/Masuit.MyBlogs.Core/Controllers/UploadController.cs
  19. 2 0
      src/Masuit.MyBlogs.Core/Controllers/UserController.cs
  20. 59 59
      src/Masuit.MyBlogs.Core/Masuit.MyBlogs.Core.xml
  21. 1 1
      src/Masuit.MyBlogs.Core/Models/DTO/AdvertisementDto.cs
  22. 1 1
      src/Masuit.MyBlogs.Core/Models/ViewModel/IndexPageViewModel.cs
  23. 2 2
      src/Masuit.MyBlogs.Core/Models/ViewModel/KeywordsRank.cs
  24. 3 2
      src/Masuit.MyBlogs.Core/Models/ViewModel/LoginRecordViewModel.cs
  25. 2 1
      src/Masuit.MyBlogs.Core/Views/Search/Search.cshtml

+ 2 - 2
src/Masuit.MyBlogs.Core/Configs/MappingProfile.cs

@@ -69,7 +69,7 @@ namespace Masuit.MyBlogs.Core.Configs
             CreateMap<UserInfo, UserInfoOutputDto>().ReverseMap();
             CreateMap<UserInfoInputDto, UserInfoOutputDto>().ReverseMap();
 
-            CreateMap<LoginRecord, LoginRecordOutputDto>().ReverseMap();
+            CreateMap<LoginRecord, LoginRecordViewModel>().ReverseMap();
 
             CreateMap<Seminar, SeminarInputDto>().ReverseMap();
             CreateMap<Seminar, SeminarOutputDto>().ReverseMap();
@@ -86,7 +86,7 @@ namespace Masuit.MyBlogs.Core.Configs
             CreateMap<Post, PostMergeRequestOutputDto>().ReverseMap();
 
             CreateMap<Advertisement, AdvertisementViewModel>().ForMember(a => a.CategoryName, e => e.MapFrom(a => a.Category.Name));
-            CreateMap<AdvertisementInputDto, Advertisement>().ForMember(a => a.CategoryId, e => e.MapFrom(d => string.IsNullOrEmpty(d.CategoryId) ? null : d.CategoryId)).ForMember(a => a.Status, e => e.Ignore()).ForMember(a => a.UpdateTime, e => e.MapFrom(a => DateTime.Now));
+            CreateMap<AdvertisementDto, Advertisement>().ForMember(a => a.CategoryId, e => e.MapFrom(d => string.IsNullOrEmpty(d.CategoryId) ? null : d.CategoryId)).ForMember(a => a.Status, e => e.Ignore()).ForMember(a => a.UpdateTime, e => e.MapFrom(a => DateTime.Now));
         }
     }
 }

+ 1 - 1
src/Masuit.MyBlogs.Core/Controllers/AdvertisementController.cs

@@ -65,7 +65,7 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// <param name="model"></param>
         /// <returns></returns>
         [HttpPost, MyAuthorize]
-        public async Task<IActionResult> Save(AdvertisementInputDto model)
+        public async Task<IActionResult> Save(AdvertisementDto model)
         {
             model.CategoryId = model.CategoryId?.Replace("null", "");
             var entity = AdsService.GetById(model.Id);

+ 2 - 1
src/Masuit.MyBlogs.Core/Controllers/FileController.cs

@@ -1,4 +1,5 @@
 using Masuit.MyBlogs.Core.Common;
+using Masuit.MyBlogs.Core.Extensions;
 using Masuit.MyBlogs.Core.Models.ViewModel;
 using Masuit.Tools.AspNetCore.ResumeFileResults.Extensions;
 using Masuit.Tools.Files;
@@ -267,7 +268,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                     return this.ResumeFile(buffer, Path.GetFileName(toFilename));
             }
 
-            return Content("null");
+            throw new NotFoundException("文件未找到");
         }
     }
 }

+ 1 - 1
src/Masuit.MyBlogs.Core/Controllers/HomeController.cs

@@ -165,7 +165,7 @@ namespace Masuit.MyBlogs.Core.Controllers
             var postsQuery = PostService.GetQuery<PostOutputDto>(p => (p.Status == Status.Pended || CurrentUser.IsAdmin)); //准备文章的查询
             var notices = NoticeService.GetPagesFromCache<DateTime, NoticeOutputDto>(1, 5, out _, n => (n.Status == Status.Display || CurrentUser.IsAdmin), n => n.ModifyDate, false).ToList(); //加载前5条公告
             var cats = CategoryService.GetQueryFromCache<string, CategoryOutputDto>(c => c.Status == Status.Available, c => c.Name).ToList(); //加载分类目录
-            var hotSearches = RedisHelper.Get<List<KeywordsRankOutputDto>>("SearchRank:Week").Take(10).ToList(); //热词统计
+            var hotSearches = RedisHelper.Get<List<KeywordsRank>>("SearchRank:Week").Take(10).ToList(); //热词统计
             var hot6Post = postsQuery.OrderBy((new Random().Next() % 3) switch
             {
                 1 => nameof(OrderBy.VoteUpCount),

+ 1 - 4
src/Masuit.MyBlogs.Core/Controllers/LinksController.cs

@@ -6,7 +6,6 @@ using Masuit.MyBlogs.Core.Models.Enum;
 using Masuit.Tools;
 using Microsoft.AspNetCore.Mvc;
 using System;
-using System.Collections.Generic;
 using System.Linq;
 using System.Net.Http;
 using System.Net.Http.Headers;
@@ -147,9 +146,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                 }
 
                 return ResultData(null, false, link + " 对方似乎没有本站的友情链接!");
-
             });
-
         }
 
         /// <summary>
@@ -186,7 +183,7 @@ namespace Masuit.MyBlogs.Core.Controllers
         [MyAuthorize]
         public ActionResult Get()
         {
-            List<Links> list = LinksService.GetAll().OrderBy(p => p.Status).ThenByDescending(p => p.Recommend).ThenByDescending(p => p.Id).ToList();
+            var list = LinksService.GetAll().OrderBy(p => p.Status).ThenByDescending(p => p.Recommend).ThenByDescending(p => p.Id).ToList();
             return ResultData(list);
         }
 

+ 2 - 2
src/Masuit.MyBlogs.Core/Controllers/LoginController.cs

@@ -1,5 +1,5 @@
 using Masuit.MyBlogs.Core.Infrastructure.Services.Interface;
-using Masuit.MyBlogs.Core.Models.DTO;
+using Masuit.MyBlogs.Core.Models.ViewModel;
 using Microsoft.AspNetCore.Mvc;
 using System;
 using System.Linq;
@@ -26,7 +26,7 @@ namespace Masuit.MyBlogs.Core.Controllers
         public ActionResult GetRecentRecord(int id)
         {
             var time = DateTime.Now.AddMonths(-1);
-            var list = LoginRecordService.GetQueryFromCache<DateTime, LoginRecordOutputDto>(r => r.UserInfoId == id && r.LoginTime >= time, r => r.LoginTime, false).ToList();
+            var list = LoginRecordService.GetQueryFromCache<DateTime, LoginRecordViewModel>(r => r.UserInfoId == id && r.LoginTime >= time, r => r.LoginTime, false).ToList();
             return ResultData(list);
         }
     }

+ 2 - 5
src/Masuit.MyBlogs.Core/Controllers/MenuController.cs

@@ -77,12 +77,9 @@ namespace Masuit.MyBlogs.Core.Controllers
             if (m == null)
             {
                 var menu = MenuService.AddEntitySaved(model.Mapper<Menu>());
-                if (menu != null)
-                {
-                    return ResultData(menu, true, "添加成功");
-                }
-                return ResultData(null, false, "添加失败");
+                return menu != null ? ResultData(menu, true, "添加成功") : ResultData(null, false, "添加失败");
             }
+
             Mapper.Map(model, m);
             bool b = MenuService.SaveChanges() > 0;
             return ResultData(null, b, b ? "修改成功" : "修改失败");

+ 1 - 6
src/Masuit.MyBlogs.Core/Controllers/MergeController.cs

@@ -114,12 +114,7 @@ namespace Masuit.MyBlogs.Core.Controllers
             var merge = PostMergeRequestService.GetById(dto.Id) ?? throw new NotFoundException("待合并文章未找到");
             Mapper.Map(dto, merge);
             var b = PostMergeRequestService.SaveChanges() > 0;
-            if (b)
-            {
-                return Merge(merge.Id);
-            }
-
-            return ResultData(null, false, "文章合并失败!");
+            return b ? Merge(merge.Id) : ResultData(null, false, "文章合并失败!");
         }
 
         /// <summary>

+ 1 - 5
src/Masuit.MyBlogs.Core/Controllers/MiscController.cs

@@ -117,11 +117,7 @@ namespace Masuit.MyBlogs.Core.Controllers
         {
             model.Content = await ImagebedClient.ReplaceImgSrc(model.Content.Trim().ClearImgAttributes());
             var e = MiscService.AddEntitySaved(model);
-            if (e != null)
-            {
-                return ResultData(null, message: "发布成功");
-            }
-            return ResultData(null, false, "发布失败");
+            return e != null ? ResultData(null, message: "发布成功") : ResultData(null, false, "发布失败");
         }
 
         /// <summary>

+ 2 - 2
src/Masuit.MyBlogs.Core/Controllers/MsgController.cs

@@ -288,7 +288,7 @@ namespace Masuit.MyBlogs.Core.Controllers
         [MyAuthorize]
         public ActionResult GetInternalMsgs(int page = 1, int size = 10)
         {
-            IEnumerable<InternalMessage> msgs = MessageService.GetPagesNoTracking(page, size, out int total, m => true, m => m.Time, false);
+            var msgs = MessageService.GetPagesNoTracking(page, size, out int total, m => true, m => m.Time, false).ToList();
             var pageCount = Math.Ceiling(total * 1.0 / size).ToInt32();
             return PageResult(msgs, pageCount, total);
         }
@@ -300,7 +300,7 @@ namespace Masuit.MyBlogs.Core.Controllers
         [MyAuthorize]
         public ActionResult GetUnreadMsgs()
         {
-            IEnumerable<InternalMessage> msgs = MessageService.GetQueryNoTracking(m => !m.Read, m => m.Time, false);
+            var msgs = MessageService.GetQueryNoTracking(m => !m.Read, m => m.Time, false).ToList();
             return ResultData(msgs);
         }
 

+ 1 - 5
src/Masuit.MyBlogs.Core/Controllers/NoticeController.cs

@@ -76,11 +76,7 @@ namespace Masuit.MyBlogs.Core.Controllers
         {
             notice.Content = await ImagebedClient.ReplaceImgSrc(notice.Content.ClearImgAttributes());
             Notice e = NoticeService.AddEntitySaved(notice);
-            if (e != null)
-            {
-                return ResultData(null, message: "发布成功");
-            }
-            return ResultData(null, false, "发布失败");
+            return e != null ? ResultData(null, message: "发布成功") : ResultData(null, false, "发布失败");
         }
 
         /// <summary>

+ 15 - 11
src/Masuit.MyBlogs.Core/Controllers/PassportController.cs

@@ -85,9 +85,11 @@ namespace Masuit.MyBlogs.Core.Controllers
                     {
                         return RedirectToAction("Index", "Home");
                     }
+
                     return Redirect(from);
                 }
             }
+
             return View();
         }
 
@@ -113,19 +115,20 @@ namespace Masuit.MyBlogs.Core.Controllers
                 return ResultData(null, false, "用户名或密码不能为空");
             }
             var userInfo = UserInfoService.Login(username, password);
-            if (userInfo != null)
+            if (userInfo == null)
             {
-                HttpContext.Session.Set(SessionKey.UserInfo, userInfo);
-                if (remem.Trim().Contains(new[] { "on", "true" })) //是否记住登录
-                {
-                    Response.Cookies.Append("username", HttpUtility.UrlEncode(username.Trim()), new CookieOptions() { Expires = DateTime.Now.AddDays(7) });
-                    Response.Cookies.Append("password", password.Trim().DesEncrypt(AppConfig.BaiduAK), new CookieOptions() { Expires = DateTime.Now.AddDays(7) });
-                }
-                HangfireHelper.CreateJob(typeof(IHangfireBackJob), nameof(HangfireBackJob.LoginRecord), "default", userInfo, ClientIP, LoginType.Default);
-                string refer = Request.Cookies["refer"];
-                return ResultData(null, true, string.IsNullOrEmpty(refer) ? "/" : refer);
+                return ResultData(null, false, "用户名或密码错误");
             }
-            return ResultData(null, false, "用户名或密码错误");
+
+            HttpContext.Session.Set(SessionKey.UserInfo, userInfo);
+            if (remem.Trim().Contains(new[] { "on", "true" })) //是否记住登录
+            {
+                Response.Cookies.Append("username", HttpUtility.UrlEncode(username.Trim()), new CookieOptions() { Expires = DateTime.Now.AddDays(7) });
+                Response.Cookies.Append("password", password.Trim().DesEncrypt(AppConfig.BaiduAK), new CookieOptions() { Expires = DateTime.Now.AddDays(7) });
+            }
+            HangfireHelper.CreateJob(typeof(IHangfireBackJob), nameof(HangfireBackJob.LoginRecord), "default", userInfo, ClientIP, LoginType.Default);
+            string refer = Request.Cookies["refer"];
+            return ResultData(null, true, string.IsNullOrEmpty(refer) ? "/" : refer);
         }
 
         /// <summary>
@@ -153,6 +156,7 @@ namespace Masuit.MyBlogs.Core.Controllers
             {
                 return ResultData(null, false, "验证码错误");
             }
+
             return ResultData(null, false, "验证码正确");
         }
 

+ 12 - 18
src/Masuit.MyBlogs.Core/Controllers/PostController.cs

@@ -440,7 +440,6 @@ namespace Masuit.MyBlogs.Core.Controllers
             });
             var content = System.IO.File.ReadAllText(HostEnvironment.WebRootPath + "/template/merge-request.html").Replace("{{title}}", post.Title).Replace("{{link}}", Url.Action("Index", "Dashboard", new { }, Request.Scheme) + "#/merge/compare?id=" + merge.Id);
             BackgroundJob.Enqueue(() => CommonHelper.SendMail("博客文章修改请求:", content, CommonHelper.SystemSettings["ReceiveEmail"]));
-
             return ResultData(null, b, b ? "您的修改请求已提交,已进入审核状态,感谢您的参与!" : "操作失败!");
         }
 
@@ -457,12 +456,7 @@ namespace Masuit.MyBlogs.Core.Controllers
             Post post = PostService.GetById(id);
             post.IsFixedTop = !post.IsFixedTop;
             bool b = PostService.SaveChanges() > 0;
-            if (b)
-            {
-                return ResultData(null, true, post.IsFixedTop ? "置顶成功!" : "取消置顶成功!");
-            }
-
-            return ResultData(null, false, "操作失败!");
+            return b ? ResultData(null, true, post.IsFixedTop ? "置顶成功!" : "取消置顶成功!") : ResultData(null, false, "操作失败!");
         }
 
         /// <summary>
@@ -807,16 +801,16 @@ namespace Masuit.MyBlogs.Core.Controllers
 
             if (schedule)
             {
-                if (timespan.HasValue && timespan.Value > DateTime.Now)
+                if (!timespan.HasValue || timespan.Value <= DateTime.Now)
                 {
-                    p.Status = Status.Schedule;
-                    p.PostDate = timespan.Value;
-                    p.ModifyDate = timespan.Value;
-                    HangfireHelper.CreateJob(typeof(IHangfireBackJob), nameof(HangfireBackJob.PublishPost), args: p);
-                    return ResultData(p.Mapper<PostOutputDto>(), message: $"文章于{timespan.Value:yyyy-MM-dd HH:mm:ss}将会自动发表!");
+                    return ResultData(null, false, "如果要定时发布,请选择正确的一个将来时间点!");
                 }
 
-                return ResultData(null, false, "如果要定时发布,请选择正确的一个将来时间点!");
+                p.Status = Status.Schedule;
+                p.PostDate = timespan.Value;
+                p.ModifyDate = timespan.Value;
+                HangfireHelper.CreateJob(typeof(IHangfireBackJob), nameof(HangfireBackJob.PublishPost), args: p);
+                return ResultData(p.Mapper<PostOutputDto>(), message: $"文章于{timespan.Value:yyyy-MM-dd HH:mm:ss}将会自动发表!");
             }
 
             PostService.AddEntity(p);
@@ -954,13 +948,13 @@ namespace Masuit.MyBlogs.Core.Controllers
         public ActionResult DisableComment(int id)
         {
             var post = PostService.GetById(id);
-            if (post != null)
+            if (post is null)
             {
-                post.DisableComment = !post.DisableComment;
-                return ResultData(null, SearchEngine.SaveChanges() > 0, post.DisableComment ? $"已禁用【{post.Title}】这篇文章的评论功能!" : $"已启用【{post.Title}】这篇文章的评论功能!");
+                return ResultData(null, false, "文章不存在");
             }
 
-            return ResultData(null, false, "文章不存在");
+            post.DisableComment = !post.DisableComment;
+            return ResultData(null, SearchEngine.SaveChanges() > 0, post.DisableComment ? $"已禁用【{post.Title}】这篇文章的评论功能!" : $"已启用【{post.Title}】这篇文章的评论功能!");
         }
 
         /// <summary>

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

@@ -5,6 +5,7 @@ using Masuit.MyBlogs.Core.Infrastructure.Services.Interface;
 using Masuit.MyBlogs.Core.Models;
 using Masuit.MyBlogs.Core.Models.DTO;
 using Masuit.MyBlogs.Core.Models.Entity;
+using Masuit.MyBlogs.Core.Models.ViewModel;
 using Masuit.Tools;
 using Microsoft.AspNetCore.Mvc;
 using System;
@@ -46,7 +47,7 @@ namespace Masuit.MyBlogs.Core.Controllers
             string key = "Search:" + ip;
             if (CacheManager.Exists(key) && CacheManager.Get(key) != wd)
             {
-                var hotSearches = RedisHelper.Get<List<KeywordsRankOutputDto>>("SearchRank:Week").Take(10).ToList();
+                var hotSearches = RedisHelper.Get<List<KeywordsRank>>("SearchRank:Week").Take(10).ToList();
                 ViewBag.hotSearches = hotSearches;
                 ViewBag.ErrorMsg = "10秒内只能搜索1次!";
                 return View(nul);
@@ -76,11 +77,11 @@ namespace Masuit.MyBlogs.Core.Controllers
                     CacheManager.Expire(key, TimeSpan.FromSeconds(10));
                 }
 
-                ViewBag.hotSearches = new List<KeywordsRankOutputDto>();
+                ViewBag.hotSearches = new List<KeywordsRank>();
                 return View(posts.Results);
             }
 
-            ViewBag.hotSearches = RedisHelper.Get<List<KeywordsRankOutputDto>>("SearchRank:Week").Take(10).ToList();
+            ViewBag.hotSearches = RedisHelper.Get<List<KeywordsRank>>("SearchRank:Week").Take(10).ToList();
             ViewData["page"] = new Pagination(page, size);
             return View(nul);
         }
@@ -110,9 +111,9 @@ namespace Masuit.MyBlogs.Core.Controllers
         {
             return ResultData(new
             {
-                month = RedisHelper.Get<List<KeywordsRankOutputDto>>("SearchRank:Month"),
-                week = RedisHelper.Get<List<KeywordsRankOutputDto>>("SearchRank:Week"),
-                today = RedisHelper.Get<List<KeywordsRankOutputDto>>("SearchRank:Today")
+                month = RedisHelper.Get<List<KeywordsRank>>("SearchRank:Month"),
+                week = RedisHelper.Get<List<KeywordsRank>>("SearchRank:Week"),
+                today = RedisHelper.Get<List<KeywordsRank>>("SearchRank:Today")
             });
         }
 

+ 1 - 0
src/Masuit.MyBlogs.Core/Controllers/SeminarController.cs

@@ -98,6 +98,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                 entry.SubTitle = seminar.SubTitle;
                 b = SeminarService.SaveChanges() > 0;
             }
+
             return ResultData(null, b, b ? "保存成功" : "保存失败");
         }
 

+ 20 - 21
src/Masuit.MyBlogs.Core/Controllers/SubscribeController.cs

@@ -1,5 +1,6 @@
 using EFSecondLevelCache.Core;
 using Hangfire;
+using Masuit.LuceneEFCore.SearchEngine.Linq;
 using Masuit.MyBlogs.Core.Common;
 using Masuit.MyBlogs.Core.Configs;
 using Masuit.MyBlogs.Core.Extensions;
@@ -16,6 +17,7 @@ using Microsoft.AspNetCore.Mvc;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Linq.Expressions;
 using System.Net;
 using System.Text;
 using WilderMinds.RssSyndication;
@@ -178,21 +180,22 @@ namespace Masuit.MyBlogs.Core.Controllers
         public ActionResult Cancel(string email)
         {
             Broadcast c = BroadcastService.Get(b => b.Email.Equals(email) && b.Status == Status.Subscribed);
-            if (c != null)
+            if (c == null)
             {
-                var ts = DateTime.Now.GetTotalMilliseconds();
-                string url = Url.Action("Subscribe", "Subscribe", new
-                {
-                    email,
-                    act = "cancel",
-                    validate = c.ValidateCode,
-                    timespan = ts,
-                    hash = (c.Email + "cancel" + c.ValidateCode + ts).AESEncrypt(AppConfig.BaiduAK)
-                }, Request.Scheme);
-                BackgroundJob.Enqueue(() => CommonHelper.SendMail("取消本站订阅", $"请<a href=\"{url}\">点击这里</a>取消订阅本站更新。", email));
-                return Content("取消订阅的链接已经发送到了您的邮箱,请到您的邮箱内进行取消订阅");
+                return Content("您输入的邮箱没有订阅本站更新,或者已经取消订阅了");
             }
-            return Content("您输入的邮箱没有订阅本站更新,或者已经取消订阅了");
+
+            var ts = DateTime.Now.GetTotalMilliseconds();
+            string url = Url.Action("Subscribe", "Subscribe", new
+            {
+                email,
+                act = "cancel",
+                validate = c.ValidateCode,
+                timespan = ts,
+                hash = (c.Email + "cancel" + c.ValidateCode + ts).AESEncrypt(AppConfig.BaiduAK)
+            }, Request.Scheme);
+            BackgroundJob.Enqueue(() => CommonHelper.SendMail("取消本站订阅", $"请<a href=\"{url}\">点击这里</a>取消订阅本站更新。", email));
+            return Content("取消订阅的链接已经发送到了您的邮箱,请到您的邮箱内进行取消订阅");
         }
 
         /// <summary>
@@ -313,17 +316,13 @@ namespace Masuit.MyBlogs.Core.Controllers
         [MyAuthorize]
         public ActionResult GetPageData(int page = 1, int size = 10, string search = "")
         {
-            List<Broadcast> list;
-            int total;
-            if (string.IsNullOrEmpty(search))
-            {
-                list = BroadcastService.GetPagesFromCache(page, size, out total, b => true, b => b.UpdateTime, false).ToList();
-            }
-            else
+            Expression<Func<Broadcast, bool>> where = b => true;
+            if (!string.IsNullOrEmpty(search))
             {
-                list = BroadcastService.GetPagesFromCache(page, size, out total, b => b.Email.Contains(search), b => b.UpdateTime, false).ToList();
+                where = where.And(b => b.Email.Contains(search));
             }
 
+            var list = BroadcastService.GetPagesFromCache(page, size, out var total, @where, b => b.UpdateTime, false).ToList();
             var pageCount = Math.Ceiling(total * 1.0 / size).ToInt32();
             return Ok(new PageDataModel(list, pageCount, total));
         }

+ 9 - 4
src/Masuit.MyBlogs.Core/Controllers/ToolsController.cs

@@ -18,6 +18,13 @@ namespace Masuit.MyBlogs.Core.Controllers
     [Route("tools")]
     public class ToolsController : BaseController
     {
+        private readonly HttpClient _httpClient;
+
+        public ToolsController(IHttpClientFactory httpClientFactory)
+        {
+            _httpClient = httpClientFactory.CreateClient();
+        }
+
         /// <summary>
         /// 获取ip地址详细信息
         /// </summary>
@@ -59,8 +66,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                 return View(address);
             }
 
-            using var client = new HttpClient();
-            var s = await client.GetStringAsync($"http://api.map.baidu.com/geocoder/v2/?location={lat},{lng}&output=json&pois=1&ak={AppConfig.BaiduAK}");
+            var s = await _httpClient.GetStringAsync($"http://api.map.baidu.com/geocoder/v2/?location={lat},{lng}&output=json&pois=1&ak={AppConfig.BaiduAK}");
             var physicsAddress = JsonConvert.DeserializeObject<PhysicsAddress>(s);
             return View(physicsAddress);
         }
@@ -94,8 +100,7 @@ namespace Masuit.MyBlogs.Core.Controllers
             }
 
             ViewBag.Address = addr;
-            using var client = new HttpClient();
-            var s = await client.GetStringAsync($"http://api.map.baidu.com/geocoder/v2/?output=json&address={addr}&ak={AppConfig.BaiduAK}");
+            var s = await _httpClient.GetStringAsync($"http://api.map.baidu.com/geocoder/v2/?output=json&address={addr}&ak={AppConfig.BaiduAK}");
             var physicsAddress = JsonConvert.DeserializeObject<PhysicsAddress>(s);
             if (Request.Method.ToLower().Equals("get"))
             {

+ 23 - 28
src/Masuit.MyBlogs.Core/Controllers/UploadController.cs

@@ -170,36 +170,31 @@ namespace Masuit.MyBlogs.Core.Controllers
         public ActionResult UeditorFileUploader()
         {
             UserInfoOutputDto user = HttpContext.Session.Get<UserInfoOutputDto>(SessionKey.UserInfo) ?? new UserInfoOutputDto();
-            Handler action = new NotSupportedHandler(HttpContext);
-            switch (Request.Query["action"])//通用
+            var action = Request.Query["action"].ToString() switch //通用
             {
-                case "config":
-                    action = new ConfigHandler(HttpContext);
-                    break;
-                case "uploadimage":
-                    action = new UploadHandler(HttpContext, new UploadConfig()
-                    {
-                        AllowExtensions = UeditorConfig.GetStringList("imageAllowFiles"),
-                        PathFormat = UeditorConfig.GetString("imagePathFormat"),
-                        SizeLimit = UeditorConfig.GetInt("imageMaxSize"),
-                        UploadFieldName = UeditorConfig.GetString("imageFieldName")
-                    });
-                    break;
-                case "uploadscrawl":
-                    action = new UploadHandler(HttpContext, new UploadConfig()
+                "config" => (Handler)new ConfigHandler(HttpContext),
+                "uploadimage" => new UploadHandler(HttpContext, new UploadConfig()
+                {
+                    AllowExtensions = UeditorConfig.GetStringList("imageAllowFiles"),
+                    PathFormat = UeditorConfig.GetString("imagePathFormat"),
+                    SizeLimit = UeditorConfig.GetInt("imageMaxSize"),
+                    UploadFieldName = UeditorConfig.GetString("imageFieldName")
+                }),
+                "uploadscrawl" => new UploadHandler(HttpContext, new UploadConfig()
+                {
+                    AllowExtensions = new[]
                     {
-                        AllowExtensions = new[] { ".png" },
-                        PathFormat = UeditorConfig.GetString("scrawlPathFormat"),
-                        SizeLimit = UeditorConfig.GetInt("scrawlMaxSize"),
-                        UploadFieldName = UeditorConfig.GetString("scrawlFieldName"),
-                        Base64 = true,
-                        Base64Filename = "scrawl.png"
-                    });
-                    break;
-                case "catchimage":
-                    action = new CrawlerHandler(HttpContext);
-                    break;
-            }
+                        ".png"
+                    },
+                    PathFormat = UeditorConfig.GetString("scrawlPathFormat"),
+                    SizeLimit = UeditorConfig.GetInt("scrawlMaxSize"),
+                    UploadFieldName = UeditorConfig.GetString("scrawlFieldName"),
+                    Base64 = true,
+                    Base64Filename = "scrawl.png"
+                }),
+                "catchimage" => new CrawlerHandler(HttpContext),
+                _ => new NotSupportedHandler(HttpContext)
+            };
 
             if (user.IsAdmin)
             {

+ 2 - 0
src/Masuit.MyBlogs.Core/Controllers/UserController.cs

@@ -22,6 +22,7 @@ namespace Masuit.MyBlogs.Core.Controllers
             {
                 return ResultData(null, false, $"用户名{username}已经存在,请尝试更换其他用户名!");
             }
+
             userInfo.Username = username;
             bool b = UserInfoService.SaveChanges() > 0;
             return ResultData(Mapper.Map<UserInfoOutputDto>(userInfo), b, b ? $"用户名修改成功,新用户名为{username}。" : "用户名修改失败!");
@@ -56,6 +57,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                 bool b = UserInfoService.ChangePassword(id, old, pwd);
                 return ResultData(null, b, b ? $"密码修改成功,新密码为:{pwd}!" : "密码修改失败,可能是原密码不正确!");
             }
+
             return ResultData(null, false, "两次输入的密码不一致!");
         }
 

+ 59 - 59
src/Masuit.MyBlogs.Core/Masuit.MyBlogs.Core.xml

@@ -313,7 +313,7 @@
             </summary>
             <returns></returns>
         </member>
-        <member name="M:Masuit.MyBlogs.Core.Controllers.AdvertisementController.Save(Masuit.MyBlogs.Core.Models.DTO.AdvertisementInputDto)">
+        <member name="M:Masuit.MyBlogs.Core.Controllers.AdvertisementController.Save(Masuit.MyBlogs.Core.Models.DTO.AdvertisementDto)">
             <summary>
             保存banner
             </summary>
@@ -4801,42 +4801,42 @@
             </summary>
             <returns>受影响的行数</returns>
         </member>
-        <member name="P:Masuit.MyBlogs.Core.Models.DTO.AdvertisementInputDto.Title">
+        <member name="P:Masuit.MyBlogs.Core.Models.DTO.AdvertisementDto.Title">
             <summary>
             标题
             </summary>
         </member>
-        <member name="P:Masuit.MyBlogs.Core.Models.DTO.AdvertisementInputDto.ImageUrl">
+        <member name="P:Masuit.MyBlogs.Core.Models.DTO.AdvertisementDto.ImageUrl">
             <summary>
             宣传图片
             </summary>
         </member>
-        <member name="P:Masuit.MyBlogs.Core.Models.DTO.AdvertisementInputDto.ThumbImgUrl">
+        <member name="P:Masuit.MyBlogs.Core.Models.DTO.AdvertisementDto.ThumbImgUrl">
             <summary>
             小宣传图片
             </summary>
         </member>
-        <member name="P:Masuit.MyBlogs.Core.Models.DTO.AdvertisementInputDto.Description">
+        <member name="P:Masuit.MyBlogs.Core.Models.DTO.AdvertisementDto.Description">
             <summary>
             描述
             </summary>
         </member>
-        <member name="P:Masuit.MyBlogs.Core.Models.DTO.AdvertisementInputDto.Url">
+        <member name="P:Masuit.MyBlogs.Core.Models.DTO.AdvertisementDto.Url">
             <summary>
             广告url
             </summary>
         </member>
-        <member name="P:Masuit.MyBlogs.Core.Models.DTO.AdvertisementInputDto.Weight">
+        <member name="P:Masuit.MyBlogs.Core.Models.DTO.AdvertisementDto.Weight">
             <summary>
             权重
             </summary>
         </member>
-        <member name="P:Masuit.MyBlogs.Core.Models.DTO.AdvertisementInputDto.Price">
+        <member name="P:Masuit.MyBlogs.Core.Models.DTO.AdvertisementDto.Price">
             <summary>
             价格
             </summary>
         </member>
-        <member name="P:Masuit.MyBlogs.Core.Models.DTO.AdvertisementInputDto.Types">
+        <member name="P:Masuit.MyBlogs.Core.Models.DTO.AdvertisementDto.Types">
             <summary>
             广告类型
             </summary>
@@ -5056,21 +5056,6 @@
             地理信息
             </summary>
         </member>
-        <member name="T:Masuit.MyBlogs.Core.Models.DTO.KeywordsRankOutputDto">
-            <summary>
-            搜索统计输出模型
-            </summary>
-        </member>
-        <member name="P:Masuit.MyBlogs.Core.Models.DTO.KeywordsRankOutputDto.Keywords">
-            <summary>
-            关键词
-            </summary>
-        </member>
-        <member name="P:Masuit.MyBlogs.Core.Models.DTO.KeywordsRankOutputDto.Count">
-            <summary>
-            搜索次数
-            </summary>
-        </member>
         <member name="T:Masuit.MyBlogs.Core.Models.DTO.LeaveMessageInputDto">
             <summary>
             留言板输入模型
@@ -5226,41 +5211,6 @@
             友链权重
             </summary>
         </member>
-        <member name="T:Masuit.MyBlogs.Core.Models.DTO.LoginRecordOutputDto">
-            <summary>
-            用户登录记录输出模型
-            </summary>
-        </member>
-        <member name="P:Masuit.MyBlogs.Core.Models.DTO.LoginRecordOutputDto.IP">
-            <summary>
-            登录点IP
-            </summary>
-        </member>
-        <member name="P:Masuit.MyBlogs.Core.Models.DTO.LoginRecordOutputDto.LoginTime">
-            <summary>
-            登录时间
-            </summary>
-        </member>
-        <member name="P:Masuit.MyBlogs.Core.Models.DTO.LoginRecordOutputDto.Province">
-            <summary>
-            所在省份
-            </summary>
-        </member>
-        <member name="P:Masuit.MyBlogs.Core.Models.DTO.LoginRecordOutputDto.PhysicAddress">
-            <summary>
-            详细地理位置
-            </summary>
-        </member>
-        <member name="P:Masuit.MyBlogs.Core.Models.DTO.LoginRecordOutputDto.LoginType">
-            <summary>
-            登录类型
-            </summary>
-        </member>
-        <member name="P:Masuit.MyBlogs.Core.Models.DTO.LoginRecordOutputDto.UserInfoId">
-            <summary>
-            登陆者ID
-            </summary>
-        </member>
         <member name="T:Masuit.MyBlogs.Core.Models.DTO.MenuInputDto">
             <summary>
             导航菜单输入模型
@@ -7103,6 +7053,21 @@
             列表内广告
             </summary>
         </member>
+        <member name="T:Masuit.MyBlogs.Core.Models.ViewModel.KeywordsRank">
+            <summary>
+            搜索统计输出模型
+            </summary>
+        </member>
+        <member name="P:Masuit.MyBlogs.Core.Models.ViewModel.KeywordsRank.Keywords">
+            <summary>
+            关键词
+            </summary>
+        </member>
+        <member name="P:Masuit.MyBlogs.Core.Models.ViewModel.KeywordsRank.Count">
+            <summary>
+            搜索次数
+            </summary>
+        </member>
         <member name="T:Masuit.MyBlogs.Core.Models.ViewModel.LeaveMessageViewModel">
             <summary>
             留言板视图模型
@@ -7168,6 +7133,41 @@
             地理信息
             </summary>
         </member>
+        <member name="T:Masuit.MyBlogs.Core.Models.ViewModel.LoginRecordViewModel">
+            <summary>
+            用户登录记录输出模型
+            </summary>
+        </member>
+        <member name="P:Masuit.MyBlogs.Core.Models.ViewModel.LoginRecordViewModel.IP">
+            <summary>
+            登录点IP
+            </summary>
+        </member>
+        <member name="P:Masuit.MyBlogs.Core.Models.ViewModel.LoginRecordViewModel.LoginTime">
+            <summary>
+            登录时间
+            </summary>
+        </member>
+        <member name="P:Masuit.MyBlogs.Core.Models.ViewModel.LoginRecordViewModel.Province">
+            <summary>
+            所在省份
+            </summary>
+        </member>
+        <member name="P:Masuit.MyBlogs.Core.Models.ViewModel.LoginRecordViewModel.PhysicAddress">
+            <summary>
+            详细地理位置
+            </summary>
+        </member>
+        <member name="P:Masuit.MyBlogs.Core.Models.ViewModel.LoginRecordViewModel.LoginType">
+            <summary>
+            登录类型
+            </summary>
+        </member>
+        <member name="P:Masuit.MyBlogs.Core.Models.ViewModel.LoginRecordViewModel.UserInfoId">
+            <summary>
+            登陆者ID
+            </summary>
+        </member>
         <member name="T:Masuit.MyBlogs.Core.Models.ViewModel.MiscViewModel">
             <summary>
             杂项页视图模型

+ 1 - 1
src/Masuit.MyBlogs.Core/Models/DTO/AdvertisementInputDto.cs → src/Masuit.MyBlogs.Core/Models/DTO/AdvertisementDto.cs

@@ -2,7 +2,7 @@
 
 namespace Masuit.MyBlogs.Core.Models.DTO
 {
-    public class AdvertisementInputDto : BaseDto
+    public class AdvertisementDto : BaseDto
     {
         /// <summary>
         /// 标题

+ 1 - 1
src/Masuit.MyBlogs.Core/Models/ViewModel/IndexPageViewModel.cs

@@ -33,7 +33,7 @@ namespace Masuit.MyBlogs.Core.Models.ViewModel
         /// <summary>
         /// 近期热搜
         /// </summary>
-        public List<KeywordsRankOutputDto> HotSearch { get; set; }
+        public List<KeywordsRank> HotSearch { get; set; }
 
         /// <summary>
         /// 热门文章

+ 2 - 2
src/Masuit.MyBlogs.Core/Models/DTO/KeywordsRankOutputDto.cs → src/Masuit.MyBlogs.Core/Models/ViewModel/KeywordsRank.cs

@@ -1,9 +1,9 @@
-namespace Masuit.MyBlogs.Core.Models.DTO
+namespace Masuit.MyBlogs.Core.Models.ViewModel
 {
     /// <summary>
     /// 搜索统计输出模型
     /// </summary>
-    public class KeywordsRankOutputDto
+    public class KeywordsRank
     {
         /// <summary>
         /// 关键词

+ 3 - 2
src/Masuit.MyBlogs.Core/Models/DTO/LoginRecordOutputDto.cs → src/Masuit.MyBlogs.Core/Models/ViewModel/LoginRecordViewModel.cs

@@ -1,12 +1,13 @@
+using Masuit.MyBlogs.Core.Models.DTO;
 using Masuit.MyBlogs.Core.Models.Enum;
 using System;
 
-namespace Masuit.MyBlogs.Core.Models.DTO
+namespace Masuit.MyBlogs.Core.Models.ViewModel
 {
     /// <summary>
     /// 用户登录记录输出模型
     /// </summary>
-    public class LoginRecordOutputDto : BaseDto
+    public class LoginRecordViewModel : BaseDto
     {
         /// <summary>
         /// 登录点IP

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

@@ -1,11 +1,12 @@
 @using System.Web
 @using Masuit.MyBlogs.Core.Models.DTO
+@using Masuit.MyBlogs.Core.Models.ViewModel
 @using Masuit.Tools
 @model IList<Masuit.MyBlogs.Core.Models.DTO.PostOutputDto>
 @{
     ViewBag.Title = "站内搜索:" + ViewBag.Keyword;
     Layout = "~/Views/Shared/_Layout.cshtml";
-    List<KeywordsRankOutputDto> hotSearches = ViewBag.hotSearches;
+    List<KeywordsRank> hotSearches = ViewBag.hotSearches;
 }
 <div class="container min-height610">
     <ol class="cd-breadcrumb triangle">