-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFollow.cshtml
121 lines (91 loc) · 3.49 KB
/
Follow.cshtml
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
@{
if (!WebSecurity.IsAuthenticated) {
Response.Redirect("~/Account/Login?returnUrl=" + Request.Url.LocalPath);
}
if ((!User.IsInRole("Member")) && (!User.IsInRole("Admin"))) {
Response.Redirect("~/Account/Login");
}
Layout = "~/_SiteLayout.cshtml";
Page.Title = "Forum Membership Page";
var db = Database.Open("StarterSite");
//Get who we're following from the URL
var followID=UrlData[0];
// Query the db filtering the followID
var forumQueryString = "SELECT * " +
"FROM ForumPosts, UserProfile " +
"WHERE ForumPosts.PostFrom = (@0)" +
"AND ForumPosts.PostFrom = UserProfile.UserId " +
"ORDER BY PostDate DESC";
//Variables for Forum Posts
var userId = WebSecurity.CurrentUserId;
var newPost = Request["messageTextArea"];
//Pull Picture from database
var username = WebSecurity.CurrentUserName;
var currentUserProfile = db.QuerySingle("SELECT Username,Picture FROM UserProfile WHERE LOWER(Email) = LOWER(@0)", username);
//Member Since
var memberSince = db.QuerySingle("SELECT MemberSince FROM UserProfile WHERE LOWER(Email) = LOWER(@0)", username);
// Post message into ForumPosts table
if (IsPost) {
newPost = Request["messageTextArea"];
if (String.IsNullOrWhiteSpace(newPost)) {
ModelState.AddError("messageTextArea","Message Text required");
}
if (ModelState.IsValid) {
var insertQuery = "INSERT INTO ForumPosts (PostMessage,PostFrom) VALUES (@0,@1)";
db.Execute(insertQuery, newPost, userId);
}
}
//var a=1;
//var b=2;
//var test= db.QuerySingle("SELECT PostFrom FROM ForumPosts");
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<h1>Hello, <a class="email" href="~/Account/Manage" title="Manage">@currentUserProfile.Username</a>!</h1>
<p>Member since: @memberSince.MemberSince</p>
<br><br>
<img src="~/Images/@currentUserProfile.Picture" alt="profImg" width="300px">
<br><br>
<!-- debug test code
<p>Current UserId = @userId</p>
<p>Current UserName = @username</p>
<p>profile image: @currentUserProfile.Picture</p>
<p>followID = @followID</p>
-->
<p>What are you doing?</p>
<form method="post" action="" >
<textarea class="messageTextArea" name="messageTextArea"></textarea>
<input class="postMessage" type="submit" value="Post Message" />
</form>
@Html.ValidationSummary("Error with your submission")
@*Testing URLData
<p>Total number of items in UrlData: @UrlData.Count</p>
<ul>
@for(var i = 0; i < UrlData.Count; i++){
<li>UrlData[@i]: @UrlData[i]</li>
}
<li>ForumPosts.PostFrom: @test.PostFrom</li>
</ul>
*@
<!-- Message Posts below -->
<!-- I used a table for now, just to get the data displaying.
TODO: reformat the messages. -->
<table border="1">
<tbody>
@foreach(var row in db.Query(forumQueryString, followID)) {
<tr>
<td><img src="~/Images/@row.Picture" alt="@username" width="100px"> </td>
<td>@row.Username </td>
<td>@row.PostMessage </td>
<td>@row.PostDate </td>
</tr>
}
</tbody>
</table>
</body>
</html>