-
Notifications
You must be signed in to change notification settings - Fork 0
/
Index.aspx.cs
88 lines (68 loc) · 2.79 KB
/
Index.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
using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
return;
// ===== DEBUG DEBUG DEBUG =====
//Session["member"] = GetMemberById(2);
// =============================
Page.Title = "Forum Index";
ListViewCategories.DataSource = new BLForum().GetParentForums();
ListViewCategories.DataBind();
Layout masterPage = Master as Layout;
masterPage.GenerateBreadCrumb(null);
LiteralTotalPosts.Text = new BLPost().CountAll().ToString();
BLMember blMember = new BLMember();
LiteralTotalMembers.Text = blMember.CountAll().ToString();
LiteralNewestMember.Text = blMember.GetNewestMember().Name;
}
protected Member GetMemberById(int id)
{
AspLinqDataContext dc = new AspLinqDataContext();
return (from Member in dc.Members where Member.Id == id select Member).SingleOrDefault();
}
protected void ListViewCategories_ItemDataBound(object sender, ListViewItemEventArgs e)
{
ListView list = (ListView)e.Item.FindControl("ListViewForums");
list.DataSource = ((Forum)e.Item.DataItem).Children;
list.DataBind();
}
protected void ListViewForums_ItemDataBound(object sender, ListViewItemEventArgs e)
{
Forum forum = e.Item.DataItem as Forum;
Panel panelSubforums = e.Item.FindControl("PanelSubforums") as Panel;
panelSubforums.Visible = forum.Children.Count > 0;
if (panelSubforums.Visible)
{
BulletedList listSubforums = e.Item.FindControl("BulletedListSubforums") as BulletedList;
foreach (Forum child in forum.Children)
{
listSubforums.Items.Add(new ListItem(child.Name, "ViewForum.aspx?id=" + child.Id));
}
}
if (forum.Topics.Count > 0)
{
BLForum blForum = new BLForum();
Literal topicCount = (Literal)e.Item.FindControl("LiteralTopicCount");
//topicCount.Text = forum.Topics.Count.ToString();
topicCount.Text = blForum.CountAllTopics(forum).ToString();
Literal postCount = (Literal)e.Item.FindControl("LiteralPostCount");
//postCount.Text = (forum.Topics.Sum(topic => topic.Posts.Count)).ToString();
postCount.Text = blForum.CountAllPosts(forum).ToString();
HyperLink hyperLinkLastPost = (HyperLink)e.Item.FindControl("HyperLinkLastPost");
Label labelLastPostInformation = (Label)e.Item.FindControl("LabelLastPostInformation");
Topic lastTopic = forum.Topics.OrderByDescending(t => t.LaatstePost.CreatedDate).First();
hyperLinkLastPost.Text = lastTopic.Title;
hyperLinkLastPost.NavigateUrl = "~/ViewTopic.aspx?id=" + lastTopic.Id.ToString();
labelLastPostInformation.Text = "By " + lastTopic.LaatstePost.Member.Name + ", " + lastTopic.LaatstePost.CreatedDate.ToShortDateString();
}
}
}