protected void btnSubmit_Click(object sender, EventArgs e) { //if page is vaild run program if (Page.IsValid) { //write data to database using (SsbContext context = new SsbContext()) { Registration registration = new Registration(); registration.FirstName = txtFirstName.Text; registration.LastName = txtLastName.Text; registration.Date = drpDate.SelectedValue; registration.Time = drpTime.SelectedValue; registration.Email = txtEmail.Text; registration.ConfirmedEmail = txtConfirmEmail.Text; registration.SinglesRegistered = chkSingles.Checked; registration.DoublesRegistered = chkDoubles.Checked; registration.CharacterId = int.Parse(drpCharacter.SelectedValue); context.Registrations.Add(registration); context.SaveChanges(); } //show confirmation info pnlForm.Visible = false; pnlConfirm.Visible = true; lblFirstName.Text = txtFirstName.Text; lblLastName.Text = txtLastName.Text; lblDate.Text = drpDate.SelectedItem.Text; lblTime.Text = drpTime.SelectedItem.Text; lblEmail.Text = txtEmail.Text; lblEmailConfirm.Text = txtConfirmEmail.Text; if (chkSingles.Checked) { lblSingles.Text = "Registered"; } else { lblSingles.Text = "Not Registered"; } if (chkDoubles.Checked) { lblDoubles.Text = "Registered"; } else { lblDoubles.Text = "Not Registered"; } lblCharacter.Text = drpCharacter.SelectedItem.Text; } }
protected void Page_Load(object sender, EventArgs e) { //get registrations from table to display them on views page using (SsbContext context = new SsbContext()) { List <Registration> registrations = context.Registrations.ToList(); foreach (Registration r in registrations) { litRegistrants.Text = litRegistrants.Text + $"<tr><td>{r.FirstName}</td><td>{r.LastName}</td><td>{r.Date}</td>" + $"<td>{r.Time}</td><td>{r.SinglesRegistered}</td><td>{r.DoublesRegistered}</td><td>{r.CharacterId}</td></tr>"; } } }