Пример #1
0
        /// <summary>
        /// When submit button on form is clicked submit record
        /// to REST database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SubmitBtn_Click(object sender, EventArgs e)
        {
            if (!FormInvalid())
            {
                Applicant newApplicant = new Applicant();
                newApplicant.FirstName      = FirstNameTxt.Text;
                newApplicant.MiddleName     = MiddleNameTxt.Text;
                newApplicant.LastName       = LastNameTxt.Text;
                newApplicant.DOB            = DataOfBirthDateTimePicker.Value;
                newApplicant.Gender         = GenderCbo.Text.Substring(0, 1);
                newApplicant.StreetAddress1 = StreetAddressTxt.Text;
                newApplicant.City           = CityTxt.Text;
                newApplicant.CountryCode    = ((Country)CountryCbo.SelectedItem).CountryCode;
                newApplicant.PhoneHome      = "5555555555";
                newApplicant.Email          = EmailTxt.Text;
                newApplicant.Citizenship    = ((Citizenship)CitizenshipCbo.SelectedItem).CitizenshipId;
                if (((Citizenship)CitizenshipCbo.SelectedItem).CitizenshipId == 5)
                {
                    newApplicant.CitizenshipOther = ((Country)CitizenshipOtherCbo.SelectedItem).CountryCode;
                }

                newApplicant.HasCriminalConviction = PastCriminalConvictionChk.Checked;
                newApplicant.OnChildAbuseRegistry  = ChildAbuseRegChk.Checked;
                newApplicant.HasDisciplinaryAction = PastDiscActionChk.Checked;
                newApplicant.IsAfricanCanadian     = AfricanCanadianChk.Checked;
                newApplicant.IsFirstNations        = FirstNationsChk.Checked;
                newApplicant.IsCurrentALP          = ALPStudentChk.Checked;
                newApplicant.HasDisability         = DocumentedDisabilityChk.Checked;
                newApplicant.Password = "******";
                try{
                    container.AddToApplicants(newApplicant);
                    container.SaveChanges();

                    NSCCModelDB.Application newApplication = new NSCCModelDB.Application();
                    newApplication.ApplicationDate = DateTime.Now;
                    newApplication.ApplicantId     = newApplicant.ApplicantId;
                    newApplication.Paid            = false;

                    container.AddToApplications(newApplication);
                    container.SaveChanges();

                    ProgramChoice newProgramChoice = new ProgramChoice();
                    newProgramChoice.ApplicationId = newApplication.ApplicationId;
                    newProgramChoice.CampusId      = ((ComboBoxItem)CampusChoice1Cbo.SelectedItem).Value;
                    // newProgramChoice.ProgramId = ((Program) ProgramChoice1Cbo.SelectedItem).ProgramId; //dont work?
                    newProgramChoice.ProgramId  = (int)ProgramChoice1Cbo.SelectedValue;
                    newProgramChoice.Preference = 1;
                    container.AddToProgramChoices(newProgramChoice);
                    container.SaveChanges();

                    ProgramChoice newProgramChoice2 = new ProgramChoice();
                    newProgramChoice2.ApplicationId = newApplication.ApplicationId;
                    newProgramChoice2.CampusId      = ((ComboBoxItem)CampusChoice2Cbo.SelectedItem).Value;
                    // newProgramChoice2.ProgramId = ((Program) ProgramChoice1Cbo.SelectedItem).ProgramId; //dont work?
                    newProgramChoice2.ProgramId  = (int)ProgramChoice2Cbo.SelectedValue;
                    newProgramChoice2.Preference = 2;
                    container.AddToProgramChoices(newProgramChoice2);
                    container.SaveChanges();
                    ErrorLbl.Text = "Successfully Added new Record";
                }
                catch (Exception ex)
                {
                    ErrorLbl.Text = ex.Message;
                }
            }
        }