Skip to content

Commit

Permalink
完成评论管理。
Browse files Browse the repository at this point in the history
  • Loading branch information
majian159 committed Jul 22, 2015
1 parent 70e5f66 commit f097020
Show file tree
Hide file tree
Showing 11 changed files with 345 additions and 75 deletions.
1 change: 1 addition & 0 deletions RabbitCMS/Web/Modules/Rabbit.Blogs/AdminMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void GetNavigation(NavigationBuilder builder)
.Add(T("文章管理"), i => i.Action("Index", "PostAdmin", new { Area = area }).LocalNavigation()
.Add(T("添加文章"), z => z.Action("Add", "PostAdmin", new { Area = area }))
.Add(T("编辑文章"), z => z.Action("Edit", "PostAdmin", new { Area = area })))
.Add(T("评论管理"), i => i.Action("Index", "CommentAdmin", new { Area = area }).LocalNavigation())
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Rabbit.Blogs.Models;
using Rabbit.Blogs.Services;
using Rabbit.Blogs.Services.Themes;
using Rabbit.Infrastructures.Data;
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net;
Expand All @@ -13,10 +13,10 @@ namespace Rabbit.Blogs.Controllers.Api
{
public class CommentController : ApiController
{
private readonly IThemeCommentService _commentService;
private readonly ICommentService _commentService;
private readonly IPostService _postService;

public CommentController(IThemeCommentService commentService, IPostService postService)
public CommentController(ICommentService commentService, IPostService postService)
{
_commentService = commentService;
_postService = postService;
Expand Down Expand Up @@ -74,10 +74,13 @@ public async Task<HttpResponseMessage> Post([FromUri]string postId, CommentViewM

public async Task<HttpResponseMessage> Delete(string id)
{
if (!await _commentService.Exist(id))
var isBatch = id.Contains(",");
if (!isBatch && !await _commentService.Exist(id))
return Request.CreateErrorResponse(HttpStatusCode.NotFound, "找不到评论信息!");

_commentService.Delete(id);
var ids = isBatch ? id.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) : new[] { id };

_commentService.Delete(ids);

return Request.CreateResponse(HttpStatusCode.OK);
}
Expand Down
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 });
}
}
}
8 changes: 5 additions & 3 deletions RabbitCMS/Web/Modules/Rabbit.Blogs/Rabbit.Blogs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
<Content Include="Views\PostAdmin\Index.cshtml" />
<Content Include="Views\CategoryAdmin\Index.cshtml" />
<Content Include="Views\PostAdmin\Edit.cshtml" />
<Content Include="Views\CommentAdmin\Index.cshtml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>
Expand All @@ -188,6 +189,7 @@
<Compile Include="AdminMenu.cs" />
<Compile Include="Controllers\Api\CommentController.cs" />
<Compile Include="Controllers\CategoryAdminController.cs" />
<Compile Include="Controllers\CommentAdminController.cs" />
<Compile Include="Controllers\PostAdminController.cs" />
<Compile Include="Controllers\Themes\FeedController.cs" />
<Compile Include="Controllers\Themes\PostController.cs" />
Expand All @@ -202,11 +204,13 @@
<Compile Include="Services\CategoryService.cs" />
<Compile Include="Services\PostService.cs" />
<Compile Include="Services\Themes\ThemeCategoryService.cs" />
<Compile Include="Services\CommentService.cs" />
<Compile Include="Services\Themes\ThemeCommentService.cs" />
<Compile Include="Services\Themes\ThemePostService.cs" />
<Compile Include="Services\Themes\ThemeTagService.cs" />
<Compile Include="Shapes\ComponentShapes.cs" />
<Compile Include="ViewModels\CategoryViewModels.cs" />
<Compile Include="ViewModels\CommentViewModels.cs" />
<Compile Include="ViewModels\PostViewModels.cs" />
<Compile Include="ViewModels\Themes\PostDetailedViewModel.cs" />
</ItemGroup>
Expand All @@ -224,9 +228,7 @@
<Name>Rabbit.Users</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Views\Feed\" />
</ItemGroup>
<ItemGroup />
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
Expand Down
2 changes: 1 addition & 1 deletion RabbitCMS/Web/Modules/Rabbit.Blogs/Scripts/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
});
}
};
$(".box-tools button").click(function () {
$(".box-tools .btn-reload").click(function () {
tableController.load();
});

Expand Down
81 changes: 81 additions & 0 deletions RabbitCMS/Web/Modules/Rabbit.Blogs/Services/CommentService.cs
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,13 @@
using Rabbit.Components.Data;
using Rabbit.Kernel;
using System;
using System.Data.Entity;
using System.Linq;
using System.Threading.Tasks;

namespace Rabbit.Blogs.Services.Themes
{
public interface IThemeCommentService : IDependency
{
IQueryable<PostCommentRecord> GetNewestList(int? count = null);

void Add(PostCommentRecord record);

IQueryable<PostCommentRecord> GetListByPost(string postId);

void Delete(string id);

Task<bool> Exist(string id);
}

internal sealed class ThemeCommentService : IThemeCommentService
Expand All @@ -40,27 +30,6 @@ public IQueryable<PostCommentRecord> GetNewestList(int? count)
return table;
}

public void Add(PostCommentRecord record)
{
_repository.Value.Create(record);
}

public IQueryable<PostCommentRecord> GetListByPost(string postId)
{
return Table().OrderBy(i => i.CreateTime).Where(i => i.Post.Id == postId);
}

public void Delete(string id)
{
var repository = _repository.Value;
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
Expand Down
30 changes: 30 additions & 0 deletions RabbitCMS/Web/Modules/Rabbit.Blogs/ViewModels/CommentViewModels.cs
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
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
@{
Layout.Styles = PageStyles();
Layout.Scripts = PageScripts();
Layout.Title = "博客分类管理";
Layout.Title = "分类管理";
}
<div class="alert alert-danger alert-dismissable" style="display: none">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
Expand All @@ -186,7 +186,7 @@
<div class="input-group" style="width: 150px;">
<input type="text" name="table_search" id="table_search" class="form-control input-sm pull-right" placeholder="标题">
<div class="input-group-btn">
<button class="btn btn-sm btn-default"><i class="fa fa-search"></i></button>
<button class="btn btn-sm btn-default btn-reload"><i class="fa fa-search"></i></button>
</div>
</div>
</div>
Expand All @@ -199,34 +199,15 @@
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr>
<td>.NET BUG(1)</td>
<td>
<span class="label label-success">显示</span>
</td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-primary btn-sm">编辑</button>
<button type="button" class="btn btn-danger btn-sm">删除</button>
</div>
</td>
</tr>
</thead><tbody>
</tbody>
</table>
</div><!-- /.box-body -->
<div class="overlay" style="display: none">
<i class="fa fa-refresh fa-spin"></i>
</div>
<div class="box-footer clearfix">
<ul class="pagination pagination-sm no-margin pull-right">
<li><a href="#"><</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">></a></li>
</ul>
<ul class="pagination pagination-sm no-margin pull-right"></ul>
</div>
</div>
<div class="box box-success" style="display:none">
Expand Down
Loading

0 comments on commit f097020

Please sign in to comment.