@@ -24,12 +24,12 @@
- @Html.Partial("/Templates/Shared/_CommonScripts.cshtml")
+ @Html.Partial("/Pages/Shared/_CommonScripts.cshtml")
@RenderSection("scripts", false)
\ No newline at end of file
diff --git a/src/SingleBlog.Web/ConfigFiles/SingleBlog.config.json b/src/SingleBlog.Web/ConfigFiles/SingleBlog.config.json
new file mode 100644
index 0000000000000000000000000000000000000000..a23258fa68d2332aa40a6d0a9a72e3e3c7be8a85
--- /dev/null
+++ b/src/SingleBlog.Web/ConfigFiles/SingleBlog.config.json
@@ -0,0 +1,7 @@
+{
+ "Port": 5000,
+ "BindUrls": null, //多个逗号分割
+ "HttpServer": "Kestrel", // Kestrel, IISItegration, HttpSys,
+ "Environment": "Development",//环境名称,Development/Production
+ "Startup": "SingleBlog.Web.Startup"
+}
diff --git a/src/SingleBlog.Web/appsettings.Development.json b/src/SingleBlog.Web/ConfigFiles/appsettings.Development.json
similarity index 100%
rename from src/SingleBlog.Web/appsettings.Development.json
rename to src/SingleBlog.Web/ConfigFiles/appsettings.Development.json
diff --git a/src/SingleBlog.Web/appsettings.json b/src/SingleBlog.Web/ConfigFiles/appsettings.json
similarity index 78%
rename from src/SingleBlog.Web/appsettings.json
rename to src/SingleBlog.Web/ConfigFiles/appsettings.json
index e8a359d5b9048ae84f5f1f0234599c8827218aea..5fff67bacc46dc31e49701866c20972d8206ea69 100644
--- a/src/SingleBlog.Web/appsettings.json
+++ b/src/SingleBlog.Web/ConfigFiles/appsettings.json
@@ -4,6 +4,5 @@
"LogLevel": {
"Default": "Warning"
}
- },
- "Template":"Default"
+ }
}
diff --git a/src/SingleBlog.Web/Models/CategoryArticleViewModel.cs b/src/SingleBlog.Web/Models/CategoryArticleViewModel.cs
new file mode 100644
index 0000000000000000000000000000000000000000..e27135b89bfbdd5f66c0453bf09575568582087b
--- /dev/null
+++ b/src/SingleBlog.Web/Models/CategoryArticleViewModel.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace SingleBlog.Web.Models
+{
+ ///
+ /// 根据指定分类查找文章的视图模型
+ ///
+ public class CategoryArticleViewModel
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
The category identifier.
+ public CategoryArticleViewModel(int categoryId)
+ {
+ this.CategoryId = categoryId;
+ }
+
+ ///
+ /// 获取或设置要获取的记录行数。默认是10.
+ ///
+ public int Take { get; set; } = 10;
+ ///
+ /// 获取或设置需要优先跳过的记录行数。
+ ///
+ public int Skip { get; set; }
+ ///
+ /// 获取分类Id。
+ ///
+ public int CategoryId { get;}
+ ///
+ /// 获取或设置一个布尔值,表示是否只获取推荐的文章。
+ ///
+ ///
+ /// 如果只获取推荐文章,则为 true;否则为 false。
+ ///
+ public bool OnlyRecommand { get; set; }
+
+ ///
+ /// 是否显示 "查看更多" 的超链接,默认 true。
+ ///
+ public bool ShowMore { get; set; } = true;
+
+ ///
+ /// “查看更多”的文本
+ ///
+ public string ShowMoreText { get; set; } = "更多内容>>";
+
+ ///
+ /// 空数据显示的文本
+ ///
+ public string EmptyDataText { get; set; } = "暂无任何内容";
+ }
+}
diff --git a/src/SingleBlog.Web/Models/RecommandArticleViewModel.cs b/src/SingleBlog.Web/Models/RecommandArticleViewModel.cs
new file mode 100644
index 0000000000000000000000000000000000000000..0848d6d336b295ad2ae217bba4750c19b23d2e9e
--- /dev/null
+++ b/src/SingleBlog.Web/Models/RecommandArticleViewModel.cs
@@ -0,0 +1,54 @@
+namespace SingleBlog.Web.Models
+{
+ ///
+ /// 获取推荐文章的设置
+ ///
+ public class RecommandArticleViewModel
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public RecommandArticleViewModel()
+ {
+
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
The category identifier.
+ public RecommandArticleViewModel(int categoryId)
+ {
+ this.CategoryId = categoryId;
+ }
+
+ ///
+ /// 分类Id,null 表示所有的分类
+ ///
+ public int? CategoryId { get; set; }
+
+ ///
+ /// 显示标题
+ ///
+ public string Title { get; set; } = "相关推荐";
+ ///
+ /// 空数据时显示的文本
+ ///
+ public string EmptyDataText { get; set; } = "暂无任何数据";
+
+ ///
+ /// 截断文章标题字数设置。标题字数超过设置的长度,则显示“...”
+ ///
+ public int ArticleTitleCut { get; set; } = 18;
+
+ ///
+ /// 是否使用新窗口打开超链接
+ ///
+ public bool NewWindow { get; set; }
+
+ ///
+ /// 获取或设置一个布尔值,如果没数据时,是否使用 的文字表示
+ ///
+ public bool ShowEmptyDataTextIfNoData { get; set; } = true;
+ }
+}
diff --git a/src/SingleBlog.Web/Templates/Default/Close.cshtml b/src/SingleBlog.Web/Pages/Close.cshtml
similarity index 100%
rename from src/SingleBlog.Web/Templates/Default/Close.cshtml
rename to src/SingleBlog.Web/Pages/Close.cshtml
diff --git a/src/SingleBlog.Web/Pages/Detail.cshtml b/src/SingleBlog.Web/Pages/Detail.cshtml
new file mode 100644
index 0000000000000000000000000000000000000000..bbe6298a0336b087d0358b453f805982c0dd19bb
--- /dev/null
+++ b/src/SingleBlog.Web/Pages/Detail.cshtml
@@ -0,0 +1,99 @@
+@page "{id}"
+@{
+ ViewBag.Title = this.Article.Title;
+}
+@inject ArticleService _articleService
+@inject SettingService _settingService
+@inject CommentService _commentService
+@functions{
+ Article Article { get; set; }
+
+ IEnumerable
RecommandArticles { get; set; }
+
+ GeneralSettingModel GeneralSetting { get; set; }
+
+ public async Task OnGetAsync(int id)
+ {
+ this.Article = await _articleService.GetArticleAsync(id);
+ this.RecommandArticles = await _articleService.GetRecommandArticlesAsync();
+ this.GeneralSetting = _settingService.GetGeneralSetting();
+ }
+
+ public async Task OnPostAsync()
+ {
+ var setting = _settingService.GetGeneralSetting();
+ var form = Request.Form;
+ var comment = new Comment
+ {
+ Content = form["Content"],
+ ArticleId = form["ArticleId"].ToString().To()
+ };
+
+ if (setting.CommentAnonymouseOnly)
+ {
+ comment.AnonymouseUserInfo = JsonConvert.SerializeObject(new AnonymousUserModel { Name = form["Name"], Email = form["Email"] });
+ }
+ else
+ {
+ comment.UserId = User.Identity.UserId();
+ }
+
+ await _commentService.SaveCommentAsync(comment);
+ return RedirectToPage("./Detail", new { id = comment.ArticleId });
+ }
+}
+
+
+
+
+
+
+
@Article.Title
+
+ - @Article.CreateTime.ToChineseDateTimeString()
+ - @Article.ViewCount
+
+
+
+
+
+
+
+
+ @Html.Partial_CommentList(this.Article.Comments)
+
+
+ @if (GeneralSetting.AllowComment)
+ {
+
+
+
+ @Html.Partial_CommentForm(this.Article.Id)
+
+
+ }
+
+
+ @Html.Partial_CategoryList()
+
+ @Html.Partial_ArticleRecommandList(new RecommandArticleViewModel { CategoryId = Article.CategoryId, Title = "相关推荐" })
+
+
+
+@Html.Hidden("ArticleContent", Html.Raw(Article.Content))
+@section styles{
+
+
+}
+@section scripts{
+
+
+
+ @Html.Partial("Shared/_ValidationScripts")
+
+}
\ No newline at end of file
diff --git a/src/SingleBlog.Web/Pages/Index.cshtml b/src/SingleBlog.Web/Pages/Index.cshtml
new file mode 100644
index 0000000000000000000000000000000000000000..b14a407ed042f97cd163ebb07e10e535f01b2c1e
--- /dev/null
+++ b/src/SingleBlog.Web/Pages/Index.cshtml
@@ -0,0 +1,19 @@
+@page
+@{
+ ViewBag.Title = "首页";
+}
+@inject CategoryService _categoryService
+@functions{
+ IEnumerable Categories { get; set; }
+ public async Task OnGetAsync()
+ {
+ this.Categories = await _categoryService.GetCategoriesAsync();
+ }
+}
+
+
+ @foreach (var item in Categories)
+ {
+ @Html.Partial_CategoryArticleCard(new CategoryArticleViewModel(item.Id))
+ }
+
\ No newline at end of file
diff --git a/src/SingleBlog.Web/Templates/Default/List.cshtml b/src/SingleBlog.Web/Pages/List.cshtml
similarity index 30%
rename from src/SingleBlog.Web/Templates/Default/List.cshtml
rename to src/SingleBlog.Web/Pages/List.cshtml
index 3029c4d6015b28eb0ca4c60811eb12926aedd650..24f2605badae9aa54c37b52a5ea6993f546492fc 100644
--- a/src/SingleBlog.Web/Templates/Default/List.cshtml
+++ b/src/SingleBlog.Web/Pages/List.cshtml
@@ -1,4 +1,4 @@
-@page
+@page "{categoryId&page=1}"
@inject ArticleService articleService
@inject CategoryService categoryService
@@ -6,29 +6,27 @@
PagedCollection Articles { get; set; }
- public async Task OnGetAsync(int page = 1, int? categoryId = null)
+ Category Category { get; set; }
+
+ public async Task OnGetAsync(int categoryId, int page = 1)
{
this.Articles = await articleService.GetArticlesAsync(new ArticleService.Query { Page = page, CategoryId = categoryId });
- if (categoryId.HasValue)
- {
- ViewBag.Title = (await categoryService.GetCategoryAsync(categoryId.Value)).Name;
- }
+ this.Category = await categoryService.GetCategoryAsync(categoryId);
+ ViewBag.Title = this.Category.Name;
}
}
-@if (Articles.Count == 0)
-{
- 暂无任何数据
-}
-
-
- @foreach (var item in Articles.Items)
- {
- -
-
-
- }
-
-
- @Html.Pagination(Articles)
-
\ No newline at end of file
+
+
+
@this.Category.Name
+
+ @Html.Partial_ArticleList(Articles.Items)
+
+ @Html.Pagination(Articles)
+
+
+
+ @Html.Partial_CategoryList()
+ @Html.Partial_ArticleRecommandList(new RecommandArticleViewModel(this.Category.Id) )
+
+
diff --git a/src/SingleBlog.Web/Templates/Shared/_CommonHead.cshtml b/src/SingleBlog.Web/Pages/Shared/_CommonHead.cshtml
similarity index 83%
rename from src/SingleBlog.Web/Templates/Shared/_CommonHead.cshtml
rename to src/SingleBlog.Web/Pages/Shared/_CommonHead.cshtml
index 0907de09981e1c1bcb73c6712e55c1d34a90a5b4..71597ea94091f764c1c40222c203b97d98e51d03 100644
--- a/src/SingleBlog.Web/Templates/Shared/_CommonHead.cshtml
+++ b/src/SingleBlog.Web/Pages/Shared/_CommonHead.cshtml
@@ -2,11 +2,10 @@
@{
var generalSetting = _settingService.GetGeneralSetting();
}
-@generalSetting.SiteName
-
+@generalSetting.SiteName
@if (!string.IsNullOrWhiteSpace(ViewBag.Title))
{
- - @ViewBag.Title;
+ - @ViewBag.Title;
}
diff --git a/src/SingleBlog.Web/Templates/Shared/_CommonScripts.cshtml b/src/SingleBlog.Web/Pages/Shared/_CommonScripts.cshtml
similarity index 100%
rename from src/SingleBlog.Web/Templates/Shared/_CommonScripts.cshtml
rename to src/SingleBlog.Web/Pages/Shared/_CommonScripts.cshtml
diff --git a/src/SingleBlog.Web/Templates/Shared/_CommonStyles.cshtml b/src/SingleBlog.Web/Pages/Shared/_CommonStyles.cshtml
similarity index 100%
rename from src/SingleBlog.Web/Templates/Shared/_CommonStyles.cshtml
rename to src/SingleBlog.Web/Pages/Shared/_CommonStyles.cshtml
diff --git a/src/SingleBlog.Web/Templates/Shared/_Footer.cshtml b/src/SingleBlog.Web/Pages/Shared/_Footer.cshtml
similarity index 95%
rename from src/SingleBlog.Web/Templates/Shared/_Footer.cshtml
rename to src/SingleBlog.Web/Pages/Shared/_Footer.cshtml
index 1471b4daf969fc472020e07f120160db907cf576..b638cfe397769889322b3475fb50697a6b1f005a 100644
--- a/src/SingleBlog.Web/Templates/Shared/_Footer.cshtml
+++ b/src/SingleBlog.Web/Pages/Shared/_Footer.cshtml
@@ -3,7 +3,7 @@
var setting = SettingService.GetGeneralSetting();
var system = SettingService.GetSystemSetting();
}
-