Skip to content

Commit ab65851

Browse files
committed
Updates to support pagination.
1 parent c90bafb commit ab65851

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

source/DasBlog.Web.Repositories/BlogManager.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class BlogManager : IBlogManager
2929
private readonly ILogger logger;
3030
private static readonly Regex stripTags = new Regex("<[^>]*>", RegexOptions.Compiled | RegexOptions.CultureInvariant);
3131
private readonly IDasBlogSettings dasBlogSettings;
32+
private const int COMMENT_PAGE_SIZE = 5;
3233

3334
public BlogManager( ILogger<BlogManager> logger, IDasBlogSettings dasBlogSettings)
3435
{
@@ -442,6 +443,20 @@ public CommentCollection GetAllComments()
442443
return dataService.GetAllComments();
443444
}
444445

446+
public List<Comment> GetCommentsFrontPage()
447+
{
448+
var comments = dataService.GetAllComments().OrderByDescending(d => d.CreatedUtc).ToList();
449+
450+
return comments.Take(COMMENT_PAGE_SIZE).ToList();
451+
}
452+
453+
public List<Comment> GetCommentsForPage(int pageIndex)
454+
{
455+
var comments = dataService.GetAllComments().OrderByDescending(d => d.CreatedUtc).ToList();
456+
457+
return comments.Skip((pageIndex) * COMMENT_PAGE_SIZE).Take(COMMENT_PAGE_SIZE).ToList();
458+
}
459+
445460
public CategoryCacheEntryCollection GetCategories()
446461
{
447462
return dataService.GetCategories();

source/DasBlog.Web.Repositories/Interfaces/IBlogManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Threading.Tasks;
34
using newtelligence.DasBlog.Runtime;
45

@@ -34,6 +35,10 @@ public interface IBlogManager
3435

3536
CommentCollection GetAllComments();
3637

38+
List<Comment> GetCommentsFrontPage();
39+
40+
List<Comment> GetCommentsForPage(int pageIndex);
41+
3742
EntryCollection SearchEntries(string searchString, string acceptLanguageHeader);
3843

3944
bool SendTestEmail();

source/DasBlog.Web.UI/Controllers/AdminController.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ public IActionResult Settings(DasBlogSettingsViewModel settings)
9191
[HttpGet("/admin/manage-comments/{postid}")]
9292
public IActionResult ManageComments(string postid)
9393
{
94-
List<CommentAdminViewModel> comments = null;
94+
var comments = new List<CommentAdminViewModel>();
9595

9696
if (postid != null)
9797
{
9898
comments = blogManager.GetComments(postid, true).Select(comment => mapper.Map<CommentAdminViewModel>(comment)).ToList();
9999
}
100100
else
101101
{
102-
comments = blogManager.GetAllComments().Select(comment => mapper.Map<CommentAdminViewModel>(comment)).ToList();
102+
comments = blogManager.GetCommentsFrontPage().Select(comment => mapper.Map<CommentAdminViewModel>(comment)).ToList();
103103
}
104104

105105
foreach (var cmt in comments)
@@ -110,6 +110,30 @@ public IActionResult ManageComments(string postid)
110110
return View(comments.OrderByDescending(d => d.Date).ToList());
111111
}
112112

113+
[HttpGet]
114+
[Route("/admin/manage-comments/page")]
115+
[HttpGet("/admin/manage-comments/page/{page}")]
116+
public IActionResult ManageCommentsByPage(int page)
117+
{
118+
var comments = new List<CommentAdminViewModel>();
119+
120+
if (page > 0)
121+
{
122+
comments = blogManager.GetCommentsForPage(page).Select(comment => mapper.Map<CommentAdminViewModel>(comment)).ToList();
123+
}
124+
else
125+
{
126+
comments = blogManager.GetCommentsFrontPage().Select(comment => mapper.Map<CommentAdminViewModel>(comment)).ToList();
127+
}
128+
129+
foreach (var cmt in comments)
130+
{
131+
cmt.Title = blogManager.GetBlogPostByGuid(new Guid(cmt.BlogPostId))?.Title;
132+
}
133+
134+
return View("ManageComments", comments.OrderByDescending(d => d.Date).ToList());
135+
}
136+
113137
public IActionResult TestEmail()
114138
{
115139
if (!blogManager.SendTestEmail())

0 commit comments

Comments
 (0)