-
Notifications
You must be signed in to change notification settings - Fork 1
/
EditComment.aspx.cs
183 lines (154 loc) · 6.53 KB
/
EditComment.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Owner: Vatsal Shah
// Product: getputs.com
// Copyright Notice: Copyright Protected. All Rights Reserved.
using System;
using System.Data;
using System.Configuration;
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;
using System.Net;
using System.Collections.Generic;
public partial class EditComment : System.Web.UI.Page
{
DBOperations dbOps;
Links links;
General general;
GUIVariables gui;
ProcessingEngine engine;
ImageEngine imageEngine;
Categories categories;
Tagger tagger;
string dateFormatString = ConfigurationManager.AppSettings["dateFormatString"];
string seperator = " | ";
private static int itemClicks = 0;
string iid = string.Empty;
string user = string.Empty; // Logged In User, different from uid.
string uid = string.Empty; // The user who submitted the item.
string cid = string.Empty;
Item item;
int _minTokensInComment = 2; // Minimum words required in the Comments Text.
int _maxTokensInComment = 500; // Minimum words required in the Comments Text.
protected void Page_Load(object sender, EventArgs e)
{
dbOps = DBOperations.Instance;
links = Links.Instance;
general = General.Instance;
gui = GUIVariables.Instance;
engine = ProcessingEngine.Instance;
imageEngine = ImageEngine.Instance;
categories = Categories.Instance;
tagger = new Tagger();
seperator = gui.Seperator;
#region CookieAlreadyExists
// START: If a getputsCookie with the Username already exists, do not show the Login Page.
if (Request.Cookies["getputsCookie"] != null)
{
HttpCookie getputsCookie = Request.Cookies["getputsCookie"];
user = dbOps.Decrypt(getputsCookie["UID"].ToString().Trim());
}
if (string.IsNullOrEmpty(user))
{
// Response.Redirect(links.LoginLink, false);
MessageLabel.Text = gui.RedFontStart + "Please login to enter a comment." + gui.RedFontEnd;
}
else
{
}
// END: If a getputsCookie with the Username already exists, do not show the Login Page.
#endregion CookieAlreadyExists
if (string.IsNullOrEmpty(Request.QueryString["uid"]) || string.IsNullOrEmpty(Request.QueryString["iid"]) || string.IsNullOrEmpty(Request.QueryString["cid"]))
{
Response.Redirect(links.FrontPageLink, true);
}
else
{
uid = Request.QueryString["uid"].Trim();
iid = Request.QueryString["iid"].Trim();
cid = Request.QueryString["cid"].Trim();
}
if (!general.IsValidInt(iid) || !general.IsValidInt(cid) || !uid.Equals(user))
{
Response.Redirect(links.FrontPageLink, true);
}
else
{
string comment = LoadComment(uid, iid, cid);
if (string.IsNullOrEmpty(comment))
{
Response.Redirect(links.FrontPageLink, true);
}
else
{
MessageLabel.Text = gui.GreenFontStart + "Your comment cannot be edited."
+ gui.LineBreak + "However, you can append more details to your previous comment." + gui.GreenFontEnd;
CurrentCommentLabel.Text = gui.GreenFontStart + "Your comment: " + gui.GreenFontEnd + gui.LineBreak + comment;
}
}
}
private string LoadComment(string uid, string iid, string cid)
{
string comment = string.Empty;
string queryString = "SELECT Comment FROM comments WHERE IID = " + iid + " AND uid = '" + uid + "' AND cid = " + cid + ";";
MySqlDataReader retList;
retList = dbOps.ExecuteReader(queryString);
if (retList != null && retList.HasRows)
{
while (retList.Read())
{
comment = Convert.ToString(retList["Comment"]);
}
}
return comment;
}
protected void EditCommentButton_Click(object sender, EventArgs e)
{
string message = string.Empty;
string editedComment = EditCommentTB.Text.Trim();
if (!string.IsNullOrEmpty(editedComment))
{
string editCommentSeperator = gui.LineBreak + gui.LineBreak + gui.GrayFontStart + uid + " made the following update on " + DateTime.Now.ToString() + gui.GrayFontEnd + gui.LineBreak + gui.LineBreak;
editedComment = general.EscapeCharacters(editedComment);
List<string> editedCommentTokens = tagger.GetTokens(editedComment, false, false, false);
if (editedCommentTokens.Count >= _minTokensInComment && editedCommentTokens.Count <= _maxTokensInComment)
{
// UPDATE comments SET Comment = CONCAT(Comment, "that is good") WHERE IID = 447 AND uid = 'vatsal' AND cid = 1;
string queryString = "UPDATE comments SET Comment = CONCAT(Comment, ' " + editCommentSeperator + editedComment + "') WHERE IID = " + iid + " AND uid = '" + uid + "' AND cid = " + cid + ";";
int retInt = dbOps.ExecuteNonQuery(queryString);
if (retInt >= 0)
{
message = gui.GreenFontStart + "New details have been appended to your comment successfully." + gui.GreenFontEnd;
EditCommentTB.Text = string.Empty;
}
else
{
message = gui.RedFontStart + "Please Try Again." + gui.RedFontEnd;
}
}
else
{
if (editedCommentTokens.Count < _minTokensInComment)
{
message = gui.RedFontStart + "Too few words to append to your comment." + gui.RedFontEnd;
}
else if(editedCommentTokens.Count > _maxTokensInComment)
{
message = gui.RedFontStart + "Too many words to append to your comment." + gui.RedFontEnd;
}
}
}
else
{
message = gui.RedFontStart + "The Comment cannot be empty" + gui.RedFontEnd;
}
MessageLabel.Text = message;
}
}