Browse Source

网站公告的bug修复

懒得勤快 5 years ago
parent
commit
2381b6e36f
1 changed files with 8 additions and 1 deletions
  1. 8 1
      src/Masuit.MyBlogs.Core/Controllers/NoticeController.cs

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

@@ -5,6 +5,7 @@ using Masuit.MyBlogs.Core.Models.DTO;
 using Masuit.MyBlogs.Core.Models.Entity;
 using Masuit.MyBlogs.Core.Models.Enum;
 using Masuit.Tools;
+using Masuit.Tools.Core.Net;
 using Masuit.Tools.Html;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
@@ -59,7 +60,6 @@ namespace Masuit.MyBlogs.Core.Controllers
             {
                 notice.MapTo<NoticeOutputDto>()
             });
-
         }
 
         /// <summary>
@@ -71,6 +71,13 @@ namespace Masuit.MyBlogs.Core.Controllers
         public ActionResult Details(int id)
         {
             var notice = NoticeService.GetById(id) ?? throw new NotFoundException("页面未找到");
+            if (!HttpContext.Session.TryGetValue("notice" + id, out _))
+            {
+                notice.ViewCount += 1;
+                NoticeService.SaveChanges();
+                HttpContext.Session.Set("notice" + id, notice.Title);
+            }
+
             return View(notice);
         }