-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
345 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
RabbitCMS/Web/Modules/Rabbit.Blogs/Controllers/CommentAdminController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Rabbit.Blogs.Services; | ||
using Rabbit.Blogs.ViewModels; | ||
using Rabbit.Infrastructures.Data; | ||
using Rabbit.Web.Mvc.UI.Admin; | ||
using System.Linq; | ||
using System.Web.Mvc; | ||
|
||
namespace Rabbit.Blogs.Controllers | ||
{ | ||
[Admin] | ||
public class CommentAdminController : Controller | ||
{ | ||
private readonly ICommentService _commentService; | ||
|
||
public CommentAdminController(ICommentService commentService) | ||
{ | ||
_commentService = commentService; | ||
} | ||
|
||
public ActionResult Index(string postId) | ||
{ | ||
ViewBag.PostId = postId; | ||
return View(); | ||
} | ||
|
||
[HttpPost] | ||
public ActionResult DataSource(string postId, int pageIndex) | ||
{ | ||
var list = _commentService.GetListByPost(postId); | ||
var pageParameter = new PageParameter(pageIndex, 10); | ||
list = pageParameter.Paged(list); | ||
var model = list.ToArray().Select(i => (CommentListViewModel)i).ToArray(); | ||
return Json(new { pageParameter.PageCount, list = model }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
RabbitCMS/Web/Modules/Rabbit.Blogs/Services/CommentService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using Rabbit.Blogs.Models; | ||
using Rabbit.Components.Data; | ||
using Rabbit.Kernel; | ||
using System; | ||
using System.Data.Entity; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Rabbit.Blogs.Services | ||
{ | ||
public interface ICommentService : IDependency | ||
{ | ||
IQueryable<PostCommentRecord> GetNewestList(int? count = null); | ||
|
||
void Add(PostCommentRecord record); | ||
|
||
IQueryable<PostCommentRecord> GetListByPost(string postId); | ||
|
||
void Delete(string[] ids); | ||
|
||
Task<bool> Exist(string id); | ||
} | ||
|
||
internal sealed class CommentService : ICommentService | ||
{ | ||
private readonly Lazy<IRepository<PostCommentRecord>> _repository; | ||
|
||
public CommentService(Lazy<IRepository<PostCommentRecord>> repository) | ||
{ | ||
_repository = repository; | ||
} | ||
|
||
#region Implementation of IThemeCommentService | ||
|
||
public IQueryable<PostCommentRecord> GetNewestList(int? count) | ||
{ | ||
IQueryable<PostCommentRecord> table = Table().OrderByDescending(i => i.CreateTime); | ||
if (count.HasValue) | ||
table = table.Take(count.Value); | ||
return table; | ||
} | ||
|
||
public void Add(PostCommentRecord record) | ||
{ | ||
_repository.Value.Create(record); | ||
} | ||
|
||
public IQueryable<PostCommentRecord> GetListByPost(string postId) | ||
{ | ||
IQueryable<PostCommentRecord> table = Table().OrderBy(i => i.CreateTime); | ||
if (!string.IsNullOrEmpty(postId)) | ||
table = table.Where(i => i.Post.Id == postId); | ||
return table; | ||
} | ||
|
||
public void Delete(string[] ids) | ||
{ | ||
var repository = _repository.Value; | ||
foreach (var id in ids) | ||
{ | ||
repository.Delete(i => i.Id == id); | ||
} | ||
} | ||
|
||
public Task<bool> Exist(string id) | ||
{ | ||
return _repository.Value.Table.AnyAsync(i => i.Id == id); | ||
} | ||
|
||
#endregion Implementation of IThemeCommentService | ||
|
||
#region Private Method | ||
|
||
private IQueryable<PostCommentRecord> Table() | ||
{ | ||
return _repository.Value.Table.Where(i => i.Post.Status == PostStatus.Publish); | ||
} | ||
|
||
#endregion Private Method | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
RabbitCMS/Web/Modules/Rabbit.Blogs/ViewModels/CommentViewModels.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Rabbit.Blogs.Models; | ||
using System; | ||
|
||
namespace Rabbit.Blogs.ViewModels | ||
{ | ||
public class CommentListViewModel | ||
{ | ||
public string Id { get; set; } | ||
|
||
public string NickName { get; set; } | ||
|
||
public string Content { get; set; } | ||
|
||
public DateTime CreateTime { get; set; } | ||
|
||
public string PostTitle { get; set; } | ||
|
||
public static explicit operator CommentListViewModel(PostCommentRecord record) | ||
{ | ||
return new CommentListViewModel | ||
{ | ||
Id = record.Id, | ||
NickName = record.NickName, | ||
Content = record.Content, | ||
CreateTime = record.CreateTime, | ||
PostTitle = record.Post.Title | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.