Skip to content

Commit a924b22

Browse files
committed
Update BlogController.cs
1 parent 96b3b84 commit a924b22

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

Blog.Core.Common/Helper/UtilConvert.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ public static string ObjToString(this object thisValue)
8282
///
8383
/// </summary>
8484
/// <param name="thisValue"></param>
85+
/// <returns></returns>
86+
public static bool IsNotEmptyOrNull(this object thisValue)
87+
{
88+
return ObjToString(thisValue) != "";
89+
}
90+
/// <summary>
91+
///
92+
/// </summary>
93+
/// <param name="thisValue"></param>
8594
/// <param name="errorValue"></param>
8695
/// <returns></returns>
8796
public static string ObjToString(this object thisValue, string errorValue)

Blog.Core/Controllers/BlogController.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@ public BlogController(IBlogArticleServices blogArticleServices, ILogger<BlogCont
4848
/// <param name="page"></param>
4949
/// <param name="bcategory"></param>
5050
/// <param name="key"></param>
51-
/// <param name="intPageSize"></param>
5251
/// <returns></returns>
5352
[HttpGet]
5453
[AllowAnonymous]
5554
//[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)]
5655
//[ResponseCache(Duration = 600)]
57-
public async Task<MessageModel<PageModel<BlogArticle>>> Get(int id, int page = 1, string bcategory = "技术博文", string key = "", int intPageSize = 6)
56+
public async Task<MessageModel<PageModel<BlogArticle>>> Get(int id, int page = 1, string bcategory = "技术博文", string key = "")
5857
{
58+
int intPageSize = 6;
5959
if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
6060
{
6161
key = "";
6262
}
6363

64-
Expression<Func<BlogArticle, bool>> whereExpression = a =>(a.bcategory == bcategory && a.IsDeleted == false) && ((a.btitle != null && a.btitle.Contains(key)) || (a.bcontent != null && a.bcontent.Contains(key)));
64+
Expression<Func<BlogArticle, bool>> whereExpression = a => (a.bcategory == bcategory && a.IsDeleted == false) && ((a.btitle != null && a.btitle.Contains(key)) || (a.bcontent != null && a.bcontent.Contains(key)));
6565

6666
var pageModelBlog = await _blogArticleServices.QueryPage(whereExpression, page, intPageSize, " bID desc ");
6767

@@ -133,6 +133,21 @@ public async Task<MessageModel<BlogViewModels>> DetailNuxtNoPer(int id)
133133
};
134134
}
135135

136+
[HttpGet]
137+
[Route("GoUrl")]
138+
[AllowAnonymous]
139+
public async Task<IActionResult> GoUrl(int id)
140+
{
141+
var response = await _blogArticleServices.QueryById(id);
142+
if (response != null && response.bsubmitter.IsNotEmptyOrNull())
143+
{
144+
response.btraffic += 1;
145+
await _blogArticleServices.Update(response);
146+
return Redirect(response.bsubmitter);
147+
}
148+
149+
return null;
150+
}
136151

137152
/// <summary>
138153
/// 获取博客测试信息 v2版本

0 commit comments

Comments
 (0)