-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewTopic.aspx.cs
150 lines (125 loc) · 3.83 KB
/
ViewTopic.aspx.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
142
143
144
145
146
147
148
149
150
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ViewTopic : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
return;
// id in querystring?
int topicId;
if (!int.TryParse(Request.QueryString["id"], out topicId))
throw new HttpException(400, "Bad Request");
Topic topic;
// bestaand topic?
if ((topic = GetTopic(topicId)) == null)
throw new HttpException(404, "Not Found");
// ja!
(Master as Layout).GenerateBreadCrumb(topic.Forum);
(Master.FindControl("BulletedListBreadCrumb") as BulletedList).Items.Add(new ListItem(topic.Title, "#"));
Page.Title = LiteralTopicTitle.Text = topic.Title;
HiddenFieldTopicId.Value = topic.Id.ToString();
RepeaterPosts.DataSource = topic.Posts.OrderBy(post => post.CreatedDate);
RepeaterPosts.DataBind();
Member member = Session["member"] as Member;
if (topic.IsLocked)
{
ButtonReply.CssClass = "btn btn-danger";
ButtonReply.Enabled = false;
ButtonReply.Text = "Locked";
ButtonReply.ToolTip = "This topic is locked. You cannot reply.";
}
else
{
if(member == null) // gast
{
ButtonReply.Enabled = false;
ButtonReply.Text = "Login to reply";
ButtonReply.ToolTip = "Only registered users can reply to topics.";
}
}
}
protected Topic GetTopic(int id)
{
AspLinqDataContext dc = new AspLinqDataContext();
return (from Topic in dc.Topics where Topic.Id == id select Topic).SingleOrDefault();
}
protected void ButtonReply_Click(object sender, EventArgs e)
{
Reply(GetTopic(int.Parse(HiddenFieldTopicId.Value)), null);
}
protected void RepeaterPosts_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
// variabelen die we nodig hebben
Forum forum = GetTopic(int.Parse(HiddenFieldTopicId.Value)).Forum;
Member member = Session["member"] as Member;
Post post = e.Item.DataItem as Post;
// post id instellen
(e.Item.FindControl("HiddenFieldPostId") as HiddenField).Value = post.Id.ToString();
// post optie lijst vinden
if (member != null)
{
BulletedList options = e.Item.FindControl("BulletedListPostOptions") as BulletedList;
bool isMod = member.IsForumModerator(forum);
// gebruiker kan eigen posts bewerken
if (isMod || post.Member.Id == member.Id)
{
options.Items.Add(new ListItem("Edit", "EditPost.aspx?id=" + post.Id));
}
// toon ip boven post
(e.Item.FindControl("PanelModeratorPostDetails") as Panel).Visible = isMod;
// moderators opties
if (isMod)
{
// eerste post mag niet verwijderd worden
if (e.Item.ItemIndex != 0)
{
// voeg delete optie toe aan lijst
options.Items.Add(new ListItem("Delete", "DeletePost.aspx?id=" + post.Id));
}
}
if (!post.Topic.IsLocked)
{
// voeg citeer optie toe aan lijst
options.Items.Add(new ListItem("Quote", "Reply.aspx"));
}
}
}
protected void BulletedListPostOptions_Click(object sender, BulletedListEventArgs e)
{
BLPost blPost = new BLPost();
BulletedList options = sender as BulletedList;
RepeaterItem item = options.Parent as RepeaterItem;
Topic topic = GetTopic(int.Parse(HiddenFieldTopicId.Value));
Post post = blPost.GetPostById(int.Parse((item.FindControl("HiddenFieldPostId") as HiddenField).Value));
switch(options.Items[e.Index].Text.ToLowerInvariant())
{
case "quote":
{
Reply(topic, post);
break;
}
case "delete":
{
blPost.Delete(post);
Response.Redirect(Request.RawUrl);
break;
}
default:
{
Response.Redirect(options.Items[e.Index].Value);
break;
}
}
}
protected void Reply(Topic topic, Post quotedPost)
{
Session["replyingToTopic"] = topic;
Session["quotedPost"] = quotedPost;
Response.Redirect("Reply.aspx");
}
}