protected void ok_Click(object sender, EventArgs e) { if (dojoSeminarRegistrationOptionID == 0) { obj = new DojoSeminarRegistrationOption(); } else { obj = new DojoSeminarRegistrationOption(dojoSeminarRegistrationOptionID); } obj.Quantity = int.Parse(tbQuantity.Text); obj.TotalFee = decimal.Parse(tbTotalFee.Text); obj.CostPerItem = decimal.Parse(tbCostPerItem.Text); if (msParentOption.SelectedItem != null && msParentOption.SelectedItem.Value != "Null") { obj.ParentOption = DojoSeminarOption.NewPlaceHolder( int.Parse(msParentOption.SelectedItem.Value)); } else { obj.ParentOption = null; } if (msParentRegistration.SelectedItem != null && msParentRegistration.SelectedItem.Value != "Null") { obj.ParentRegistration = DojoSeminarRegistration.NewPlaceHolder( int.Parse(msParentRegistration.SelectedItem.Value)); } else { obj.ParentRegistration = null; } if (editOnAdd) { dojoSeminarRegistrationOptionID = obj.Save(); } else { obj.Save(); } if (resetOnAdd) { tbQuantity.Text = string.Empty; tbTotalFee.Text = string.Empty; tbCostPerItem.Text = string.Empty; msParentOption.SelectedIndex = 0; msParentRegistration.SelectedIndex = 0; } OnUpdated(EventArgs.Empty); }
private void create() { setValidators(Tab.Create); Page.Validate(); if (!Page.IsValid) { return; } // Create a new registration if it does not already exist. Be sure to create // the registration in proper order; contact, registration, options. If // Rappahanock is enabled, create the sales order for the item. SeminarRegistrationBuilder builder = null; if (registrationID == 0) { builder = new SeminarRegistrationBuilder(); registration = builder.Registration; registrationOptions = builder.Options; registration.Contact = new GreyFoxContact(DojoSeminarRegistrationManager.ContactTable); // Set a SessionID for security using either the username // or ASP.net SessionID if (Page.User.Identity.Name != string.Empty) { registration.SessionID = Page.User.Identity.Name; } else { registration.SessionID = Page.Session.SessionID; } } else { // Be sure to remove the registration from the cart if // Rappahanock processing is activated. try { builder = new SeminarRegistrationBuilder(registrationID); } catch { selectedTab = Tab.Locked; return; } registration = builder.Registration; registrationOptions = builder.Options; // Check for SessionID for Security if (registration.SessionID != Page.Session.SessionID & registration.SessionID != Page.User.Identity.Name) { selectedTab = Tab.Locked; return; } // If the registration has a payment amount over zero, // be sure to lock it to remove a vulnerability. if (registration.PaymentAmount > 0) { selectedTab = Tab.Locked; return; } if (paymentMode == RegistrationPaymentMode.Rappahanock) { builder.RemoveFromCart(); } } registration.RegistrationDate = DateTime.Now; registration.Status = 0; registration.Contact.ParseName(tbName.Text); registration.Contact.ParseAddress(tbAddress1.Text, tbAddress2.Text, tbCity.Text, tbStateProvince.Text, tbPostalCode.Text, tbCountry.Text); registration.Contact.ParsePhones(tbHomePhone.Text, tbWorkPhone.Text, string.Empty, string.Empty, string.Empty); registration.Contact.Email1 = tbEmail1.Text; registration.Contact.Save(); registration.ParentSeminar = seminar; registration.classUnits = int.Parse(ddClassUnits.SelectedItem.Value); registrationID = registration.Save(); // Set options for the registration by first clearing the options // already associated with the registration then recreating them // from current selections. DojoSeminarRegistrationOptionManager.ClearOptions(registration); registrationOptions.Clear(); // Loop through the form's post back data looking for the lineOption // and quantity keys. Setup the associated options with the // current registration only if selected or the quantity is not // zero. string[] allKeys = Context.Request.Form.AllKeys; int optionId; int quantity = 0; for (int x = 0; x < allKeys.Length; x++) { if (!allKeys[x].StartsWith(ClientID + "___option") & !allKeys[x].StartsWith(ClientID + "___qty")) { continue; } if (allKeys[x].StartsWith(ClientID + "___option")) { // Parse OptionID Selected optionId = int.Parse(allKeys[x].Substring( ClientID.Length + 9, allKeys[x].Length - (ClientID.Length + 9))); quantity = 1; } else { // Parse OptionID and Quantity Selected and be sure // to ignore quantities less than 1, otherwise some // clever registrants will get some discounts! optionId = int.Parse(allKeys[x].Substring( ClientID.Length + 6, allKeys[x].Length - (ClientID.Length + 6))); quantity = int.Parse(Context.Request.Form[ClientID + "___qty" + optionId.ToString()]); if (quantity < 1) { continue; } } // Find the lineOption in the seminar's list of available options then // add the lineOption and save it. foreach (DojoSeminarOption seminarOption in seminar.Options) { if (optionId == seminarOption.iD) { DojoSeminarRegistrationOption registrationOption = new DojoSeminarRegistrationOption(); registrationOption.ParentRegistration = registration; registrationOption.ParentOption = seminarOption; registrationOption.CostPerItem = seminarOption.Fee; registrationOption.Quantity = quantity; registrationOption.TotalFee = seminarOption.Fee * registrationOption.Quantity; registrationOption.Save(); registrationOptions.Add(registrationOption); break; } } } // Save the registration again to update quantities and fees. registration.CalculateFee(registrationOptions); registration.Save(); if (paymentMode == RegistrationPaymentMode.Rappahanock) { builder.AddToCart(); } selectedTab = Tab.Verify; }