-
Notifications
You must be signed in to change notification settings - Fork 0
/
GuestBook.aspx.cs
117 lines (98 loc) · 3.52 KB
/
GuestBook.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
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class GuestBook : DefaultPage
{
private int _pageid;
public int pageid
{
get { return _pageid; }
set { _pageid = value; }
}
protected void PopulateRepeater()
{
NbpDataContext db = new NbpDataContext();
var q = from p in db.guestbooks
orderby p.guestbookTimestamp descending
select p;
rpGuestbookViewer.DataSource = q;
rpGuestbookViewer.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["p"] != null)
{
try
{
pageid = Convert.ToInt32(Request.QueryString["p"]);
}
catch
{
pageid = 0;
}
}
if (pageid == 0)
{
PopulateRepeater();
}
MultiView1.ActiveViewIndex = pageid;
}
protected void btnGuestbookSubmit_Click(object s, EventArgs e)
{
if (Page.IsValid)
{
NbpDataContext db = new NbpDataContext();
guestbook g = new guestbook();
g.guestbookId = Guid.NewGuid();
g.guestbookEmail = txtEmail.Text.ToString();
g.guestbookRelationship = txtRelationship.Text.ToString();
g.guestbookSourceIp = Request.ServerVariables["REMOTE_ADDR"];
g.guestbookText = txtText.Text.ToString();
g.guestbookTimestamp = DateTime.Now;
g.guestbookAuthor = txtAuthor.Text.ToString();
db.guestbooks.InsertOnSubmit(g);
db.SubmitChanges();
Session["nbpEmail"] = txtEmail.Text.ToString();
Session["nbpName"] = txtAuthor.Text.ToString();
// audit stuff
audit a = new audit();
a.auditId = Guid.NewGuid();
a.auditRemoteAddr = Request.ServerVariables["REMOTE_ADDR"].ToString();
a.auditRequestedUrl = "Guestbook.aspx";
a.auditSessionEmail = Session["nbpEmail"] != null ? Session["nbpEmail"].ToString() : "";
a.auditSessionId = Session.SessionID.ToString();
a.auditSessionName = Session["nbpName"] != null ? Session["nbpName"].ToString() : "";
a.auditTimestamp = DateTime.Now;
a.auditType = "Guestbook Signed";
a.auditDescription = "E-Mail: " + txtEmail.Text.ToString() +
" Relationship: " + txtRelationship.Text.ToString() +
" Text: " + txtText.Text.ToString();
a.auditReferrer = Request.UrlReferrer.AbsolutePath.ToString();
a.auditLogonUser = Request.ServerVariables["LOGON_USER"];
db.audits.InsertOnSubmit(a);
db.SubmitChanges();
MultiView1.ActiveViewIndex = 2;
MultiView1.DataBind();
}
else
{
foreach (BaseValidator valControl in Page.Validators)
{
WebControl aControl = (WebControl)Page.FindControl(valControl.ControlToValidate);
if (!valControl.IsValid)
aControl.BackColor = System.Drawing.Color.Yellow;
else
aControl.BackColor = System.Drawing.Color.White;
}
}
}
}