-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegistration.aspx.cs
More file actions
77 lines (64 loc) · 2.72 KB
/
Registration.aspx.cs
File metadata and controls
77 lines (64 loc) · 2.72 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace LastCallServer
{
public partial class Registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lastcallEntities db = new lastcallEntities();
foodtype[] foodtypes = (from x in db.foodtypes select x).ToArray();
string s = "";
bool b = false;
foreach (foodtype f in foodtypes)
{
s += "<asp:CheckBox ID=\"pref" + f.id.ToString() + "\" runat=\"server\" Checked=\"false\" Text=\"" + f.foodtype1 + "\" onclick=\"preference(this, " + f.id.ToString() + ")\"/>";
s += (b ? "<br/>" : " ");
b = !b;
}
preferences.Controls.Clear();
preferences.Controls.Add(Page.ParseControl(s));
}
protected void SubmitButton_Click(object sender, EventArgs e)
{
lastcallEntities db = new lastcallEntities();
subscriber s = (from x in db.subscribers where x.email == email.Text select x).FirstOrDefault();
if (s != null)
{
ErrorMessage.Text = "Username is already registered";
return;
}
// The new subscriber record
s = new subscriber() {
deliveryaddress = address.Text,
email = email.Text,
emailoffers = (byte)(emailoffers.Checked ? 1 : 0),
friendlyname = friendlyname.Text,
onmailinglist = (byte)(mailinglist.Checked ? 1 : 0),
password = password.Text,
phone = telephone.Text,
textoffers = (byte)(textoffers.Checked ? 1 : 0),
};
string[] userprefs = foodprefs.Value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
// The subscriber's food preferences
foodpreference [] preferences = new foodpreference[userprefs.Length];
for (int i = 0; i < userprefs.Length; i++)
{
preferences[i] = new foodpreference()
{
subscriberid = s.id,
preferenceid = Int32.Parse(userprefs[i])
};
}
// Extremely wonderful Entity Framework goodness. The associated foodpreferences records will be created as the subscriber record is saved.
s.foodpreferences = preferences;
db.subscribers.Add(s);
db.SaveChanges();
db.Dispose();
}
}
}