-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.aspx.cs
More file actions
238 lines (178 loc) · 8.12 KB
/
user.aspx.cs
File metadata and controls
238 lines (178 loc) · 8.12 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class user : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
protected void Page_Init(object sender, EventArgs e) {
int id;
if (Request.QueryString["id"] == null || !int.TryParse(Request.QueryString["id"], out id) || !global::User.Exists(id)) {
Response.Redirect("users.aspx");
} else if (!IsPostBack) {
User usr = global::User.GetUser(id);
litTitle.Text = usr.Firstname + " " + usr.Lastname;
profilePic.ImageUrl = "files/users/imgs/" + usr.ImageName;
firstname.Text = usr.Firstname;
lastname.Text = usr.Lastname;
if (usr.Description != null) {
descrTextPanel.Text = "<p>" + string.Join("</p>\n<p>", usr.Description.Split('\n')) + "</p>\n";
}
if (Session["LoggerID"] != null) {
contactViews.ActiveViewIndex = 1;
buttonPanel.Visible = true;
if (usr.ShowMail) {
mailPanel.Visible = true;
emailaddress.Text = usr.GetEmail();
emailLink.CommandArgument = "mailto:" + usr.GetEmail();
}
phonenr.Text = usr.Telephone;
Logger log;
if((log = Logger.GetLogger(Session["LoggerID"])) != null && log.IsUser) {
pmPanel.Visible = true;
PrivateMessageUser.PostBackUrl = "inbox.aspx?mode=new&to=" + usr.ID;
}
CVUser.CommandArgument = usr.Cv;
}
tagRepeater.DataSource = usr.GetTags();
tagRepeater.DataBind();
Logger logger;
if (Session["LoggerID"] != null && (logger = Logger.GetLogger(Session["LoggerID"])) != null && logger.UserId == id) {
// Show Edit buttons
infoEdit.Visible = true;
tagsEdit.Visible = true;
// Add ID's to submit buttons
submitInfo.CommandArgument = usr.ID.ToString();
submitTag.CommandArgument = usr.ID.ToString();
cancelInfo.CommandArgument = usr.ID.ToString();
cancelTags.CommandArgument = usr.ID.ToString();
// Persist
txtEmail.Text = usr.Email;
chMail.Checked = usr.ShowMail;
txtPhone.Text = usr.Telephone;
txtDescr.Text = usr.Description;
tagEditRepeater.DataSource = usr.GetTags();
tagEditRepeater.DataBind();
}
}
}
protected void CVUser_Click(object sender, CommandEventArgs e) {
Response.Redirect("/files/users/cvs/" + e.CommandArgument);
}
protected void emailLink_Command(object sender, CommandEventArgs e) {
Response.Redirect(e.CommandArgument.ToString());
}
#region - Edit -
protected void Show_Command(object sender, CommandEventArgs e) {
switch (e.CommandName) {
case "info": editInfo.ActiveViewIndex = 1; break;
case "tags": editTags.ActiveViewIndex = 1; break;
}
}
protected void Cancel_Command(object sender, CommandEventArgs e) {
int id;
User usr;
if (int.TryParse(e.CommandArgument.ToString(), out id) && (usr = global::User.GetUser(id)) != null) {
switch (e.CommandName) {
case "info":
txtEmail.Text = usr.Email;
txtPhone.Text = usr.Telephone;
txtDescr.Text = usr.Description;
editInfo.ActiveViewIndex = 0;
break;
case "tags":
tagRepeater.DataSource = usr.GetTags();
tagRepeater.DataBind();
editTags.ActiveViewIndex = 0;
break;
}
}
}
protected void Edit_Command(object sender, CommandEventArgs e) {
int id;
User usr;
if (int.TryParse(e.CommandArgument.ToString(), out id) && (usr = global::User.GetUser(id)) != null) {
switch (e.CommandName) {
case "info":
Page.Validate("info");
if (Page.IsValid) {
string img = null;
string cv = null;
if (fileImage.HasFile) {
string fn = System.IO.Path.GetFileName(fileImage.PostedFile.FileName);
img = fn;
int i = 0;
while (global::User.ImageExists(img)) {
i++;
img = i + img;
}
string loc = Server.MapPath("~/files/users/imgs/" + img);
try {
fileImage.PostedFile.SaveAs(loc);
} catch {
throw; //TODO: errorhandling
}
}
if (fileCv.HasFile) {
string fn = System.IO.Path.GetFileName(fileImage.PostedFile.FileName);
cv = fn;
int i = 0;
while (global::User.ImageExists(cv)) {
i++;
cv = i + cv;
}
string loc = Server.MapPath("~/files/users/cvs/" + cv);
try {
fileImage.PostedFile.SaveAs(loc);
} catch {
throw; //TODO: errorhandling
}
}
usr.UpdateInfo(img, txtEmail.Text, txtPhone.Text, cv, txtDescr.Text);
profilePic.ImageUrl = "files/users/imgs/" + usr.ImageName;
if (usr.Description != null) descrTextPanel.Text = string.Format("<p>{0}</p>\n", string.Join("</p>\n<p>", usr.Description.Split('\n')));
emailaddress.Text = usr.GetEmail();
emailLink.CommandArgument = "mailto:" + usr.GetEmail();
phonenr.Text = usr.Telephone;
CVUser.CommandArgument = usr.Cv;
editInfo.ActiveViewIndex = 0;
}
break;
case "tags":
Page.Validate("tags");
if (Page.IsValid) {
usr.AddTag(txtTag.Text.Trim());
txtTag.Text = "";
tagEditRepeater.DataSource = usr.GetTags();
tagEditRepeater.DataBind();
}
break;
}
}
}
protected void custImage_ServerValidate(object source, ServerValidateEventArgs args) {
if (fileImage.HasFile) {
if (fileImage.PostedFile.ContentType.ToLower() != "image/jpg" && fileImage.PostedFile.ContentType.ToLower() != "image/jpeg" && fileImage.PostedFile.ContentType.ToLower() != "image/png")
args.IsValid = false;
}
}
protected void tagEditRepeater_ItemCommand(object source, RepeaterCommandEventArgs e) {
int id;
User usr;
Logger log;
if (int.TryParse(Request.QueryString["id"].ToString(), out id) && (usr = global::User.GetUser(id)) != null &&
Session["LoggerID"] != null && (log = Logger.GetLogger(Session["LoggerID"])) != null && log.IsUser && usr.ID == log.UserId) {
usr.RemoveTag(((LinkButton)e.CommandSource).CommandArgument.ToString());
tagEditRepeater.DataSource = usr.GetTags();
tagEditRepeater.DataBind();
}
}
protected void custTag_ServerValidate(object source, ServerValidateEventArgs args) {
if (IsValid) {
if (args.Value.Trim().Length > 20) args.IsValid = false;
}
}
#endregion
}