forked from wojilu/wojilu
/
PostController.cs
executable file
·142 lines (99 loc) · 4.64 KB
/
PostController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Copyright (c) 2010, www.wojilu.com. All rights reserved.
*/
using System;
using System.Collections.Generic;
using wojilu.ORM;
using wojilu.Web.Mvc;
using wojilu.Web.Mvc.Attr;
using wojilu.Apps.Forum.Domain;
using wojilu.Apps.Forum.Service;
using wojilu.Apps.Forum.Interface;
using wojilu.Web.Controller.Forum.Utils;
using wojilu.Common.AppBase.Interface;
using wojilu.Members.Users.Domain;
using wojilu.Web.Controller.Common;
namespace wojilu.Web.Controller.Forum {
[App( typeof( ForumApp ) )]
public partial class PostController : ControllerBase {
public virtual IAttachmentService attachService { get; set; }
public virtual IForumBoardService boardService { get; set; }
public virtual IForumPostService postService { get; set; }
public virtual IForumTopicService topicService { get; set; }
public virtual IModeratorService moderatorService { get; set; }
public PostController() {
boardService = new ForumBoardService();
topicService = new ForumTopicService();
postService = new ForumPostService();
attachService = new AttachmentService();
moderatorService = new ModeratorService();
}
public override void CheckPermission() {
ForumPost post = postService.GetById( ctx.route.id, ctx.owner.obj );
if (post == null) {
echo( alang( "exPostNotFound" ) );
return;
}
ForumBoard board = getTree().GetById( post.ForumBoardId );
if (board == null) {
echo( alang( "exBoardNotFound" ) );
return;
}
SecurityHelper.Check( this, board );
}
private Tree<ForumBoard> _tree;
private Tree<ForumBoard> getTree() {
if (_tree == null) _tree = new Tree<ForumBoard>( boardService.GetBoardAll( ctx.app.Id, ctx.viewer.IsLogin ) );
return _tree;
}
public virtual void Show( long id ) {
ForumPost post = postService.GetById( id, ctx.owner.obj );
ForumBoard board = getTree().GetById( post.ForumBoardId );
postService.AddHits( post );
ForumTopic topic = topicService.GetById( post.TopicId, ctx.owner.obj );
if (topic == null) {
echo( alang( "exTopicNotFound" ) );
return;
}
topicService.AddHits( topic );
ctx.Page.SetTitle( post.Title, board.Name );
List<ForumBoard> pathboards = getTree().GetPath( post.ForumBoardId );
set( "location", ForumLocationUtil.GetPost( pathboards, post, ctx ) );
List<ForumPost> posts = new List<ForumPost>();
posts.Add( post );
List<Attachment> attachments = attachService.GetByPost( post.Id );
ctx.SetItem( "forumBoard", board );
ctx.SetItem( "forumTopic", topic );
ctx.SetItem( "posts", posts );
ctx.SetItem( "attachs", attachments );
ctx.SetItem( "pageSize", -1 );
load( "currentPost", new TopicController().PostLoop );
set( "topic.Url", to( new TopicController().Show, post.TopicId ) );
set( "moderatorJson", moderatorService.GetModeratorJson( board ) );
set( "creatorId", topic.Creator.Id );
set( "tagAction", to( new Edits.TagController().SaveTag, topic.Id ) );
DataPage<ForumPost> replyList = postService.GetPageList( post.TopicId, 200, 0 );
bindReplyList( replyList, post.Id );
}
private void bindReplyList( DataPage<ForumPost> results, long currentPostId ) {
IBlock block = getBlock( "replypost" );
List<ForumPost> replyList = results.Results;
foreach (ForumPost post in replyList) {
if (post.Creator == null) continue;
block.Set( "p.MemberUrl", toUser( post.Creator ) );
block.Set( "p.MemberName", post.Creator.Name );
block.Set( "p.Title", post.Title );
block.Set( "p.Length", post.Content.Length );
block.Set( "p.CreateTime", post.Created );
block.Set( "p.Hits", post.Hits );
String plink = post.ParentId == 0 ? to( new TopicController().Show, post.TopicId ) : alink.ToAppData( post );
block.Set( "p.Url", plink );
String pclass = post.Id == currentPostId ? "red strong" : "";
block.Set( "p.Class", pclass );
block.Next();
}
String page = results.PageCount > 1 ? results.PageBar : "";
set( "replyPage", page );
}
}
}