-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDefault.aspx.cs
128 lines (112 loc) · 4.08 KB
/
Default.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using System.Threading.Tasks;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Clear the last session for adding additional entries
Session.Clear();
}
protected void clearButton_Click(object sender, EventArgs e)
{
// Clear all TextBoxes
name.Text = String.Empty;
games.Text = String.Empty;
live.Text = String.Empty;
psn.Text = String.Empty;
steam.Text = String.Empty;
wiiu.Text = String.Empty;
// Hide Panels
livePanel.Visible = false;
psnPanel.Visible = false;
steamPanel.Visible = false;
wiiuPanel.Visible = false;
delPanel.Visible = false;
// Reset outputLabel
outputLabel.Text = String.Empty;
delete.Visible = false;
submitButton.Visible = false;
}
protected void verifyButton_Click(object sender, EventArgs e)
{
// Validation
if (name.Text == "" || !name.Text.Contains(" "))
outputLabel.Text = "You must provide your full name";
else if (live.Text == "" && psn.Text == "" && steam.Text == "" && wiiu.Text == "")
outputLabel.Text = "You must provide at least a single tag";
else if (live.Text.Contains(" ") || psn.Text.Contains(" ") || steam.Text.Contains(" ") || wiiu.Text.Contains(" "))
outputLabel.Text = "Tags may not contain whitespace";
else
{
// Display output for each TextBox that contains data
outputLabel.Text = String.Format("{0} Name: {1}",
"<br />",
name.Text);
if (games.Text != "")
outputLabel.Text += "<br /> Games: " + games.Text;
if (live.Text != "")
outputLabel.Text += "<br /> Live: " + live.Text;
if (psn.Text != "")
outputLabel.Text += "<br /> PSN: " + psn.Text;
if (steam.Text != "")
outputLabel.Text += "<br /> Steam: " + steam.Text;
if (wiiu.Text != "")
outputLabel.Text += "<br /> WiiU: " + wiiu.Text;
outputLabel.Text += "<br />";
delete.Visible = true;
delPanel.Visible = true;
submitButton.Visible = true;
}
}
protected void submitButton_Click(object sender, EventArgs e)
{
delPanel.Visible = false;
submitButton.Visible = false;
// Cancel game names that contain apostrophe
string gamesList = games.Text.Replace("'", "''");
// Retrieves info from textboxes
var document = new BsonDocument
{
{ "name", name.Text },
{ "live", live.Text },
{ "psn", psn.Text },
{ "steam", steam.Text },
{ "wiiu", wiiu.Text },
{ "games", games.Text },
{ "delKey", delete.Text }
};
// Start a session, allowing for deletion from database
Session.Add("Name", name.Text);
var collection = Global.database.GetCollection<BsonDocument>("Tags");
// Upon successful insertion
collection.InsertOne(document);
outputLabel.Text += "<br />" + Session.Contents[0] + ", your gamertag(s) have been added! <br /> <a href=\"./ViewAll.aspx\"> Click Here To View All Entries </a>";
}
/*
* Reveal Each TextBox's Panel
*/
protected void liveImg_Click(object sender, ImageClickEventArgs e)
{
livePanel.Visible = true;
}
protected void psnImg_Click(object sender, ImageClickEventArgs e)
{
psnPanel.Visible = true;
}
protected void steamImg_Click(object sender, ImageClickEventArgs e)
{
steamPanel.Visible = true;
}
protected void wiiuImg_Click(object sender, ImageClickEventArgs e)
{
wiiuPanel.Visible = true;
}
}