private string Submit() { var id = Guid.Parse(RecordId); var returnMessage = string.Empty; try { using (var dataContext = new nChangerDb()) { var dbEntry = dataContext.ParentInformations.Find(id); if (dbEntry != null) { dbEntry.FatherFirstName = txtFatherFirstName.Text; dbEntry.FatherMiddleName = txtFatherMiddleName.Text; dbEntry.FatherLastName = txtFatherLastName.Text; dbEntry.FatherOtherLastName = txtFatherLastNameOther.Text; dbEntry.MotherFirstName = txtMotherFirstName.Text; dbEntry.MotherMiddleName = txtMotherMiddleName.Text; dbEntry.MotherLastNameWhenBorn = txtMotherLastNameBorn.Text; dbEntry.MotherLastNamePresent = txtMotherLastNamePresent.Text; dbEntry.MotherLastNameOther = txtMotherLastNameOther.Text; dbEntry.EntryDate = DateTime.Today; dbEntry.EntryIP = CommonFunctions.GetIpAddress(); dbEntry.IsActive = true; dbEntry.EntryId = UserId; dataContext.Entry(dbEntry).State = EntityState.Modified; } else { var entry = new ParentInformation() { Id = id, PdfFormTemplateId = Guid.Parse(CurrentId), UserId = UserId, FatherFirstName = txtFatherFirstName.Text, FatherMiddleName = txtFatherMiddleName.Text, FatherLastName = txtFatherLastName.Text, FatherOtherLastName = txtFatherLastNameOther.Text, MotherFirstName = txtMotherFirstName.Text, MotherMiddleName = txtMotherMiddleName.Text, MotherLastNameWhenBorn = txtMotherLastNameBorn.Text, MotherLastNamePresent = txtMotherLastNamePresent.Text, MotherLastNameOther = txtMotherLastNameOther.Text, EntryDate = DateTime.Today, EntryIP = CommonFunctions.GetIpAddress(), IsActive = true, EntryId = UserId }; dataContext.ParentInformations.Add(entry); } dataContext.SaveChanges(); returnMessage = "Data submitted successfully!"; } } catch (DbEntityValidationException ex) { returnMessage = ex.EntityValidationErrors.SelectMany(eve => eve.ValidationErrors).Aggregate(returnMessage, (current, ve) => current + (ve.PropertyName + " Error Msg:" + ve.ErrorMessage)); } return returnMessage; }
private string Submit() { var id = Guid.Parse(RecordId); var returnMessage = string.Empty; try { using (var dataContext=new nChangerDb()) { var dbEntry = dataContext.PersonalInformations.Find(id); if (dbEntry != null) { dbEntry.PresentFirstName = txtPresentFirstName.Text; dbEntry.PresentMiddleName = txtPresentMiddleName.Text; dbEntry.PresentLastName = txtPresentLastName.Text; dbEntry.Sex =rdListSex.SelectedIndex==-1?string.Empty: rdListSex.SelectedItem.Value; dbEntry.MailAddStreetNo = txtMailAddStreetNo.Text; dbEntry.MailAddPOBox = txtMailAddPOBox.Text; dbEntry.MailAddAptSuitNo = txtMailAddAptSuitNo.Text; dbEntry.MailAddBuzzerNo = txtMailAddBuzzerNo.Text; dbEntry.MailAddCityTownVillage = txtMailAddCityTownVillage.Text; dbEntry.MailAddProvience = txtMailAddProvience.Text; dbEntry.MailAddPostalCode = txtMailAddPostalCode.Text; dbEntry.MailAddHomePhoneCode = txtMailAddHomePhoneCode.Text; dbEntry.MailAddHomePhoneNo = txtMailAddHomePhoneNo.Text; dbEntry.MailAddWorkPhoneCode = txtMailAddWorkPhoneCode.Text; dbEntry.MailAddWorkPhoneNo = txtMailAddWorkPhoneNo.Text; dbEntry.LivedInOntarioYears = string.IsNullOrEmpty(txtLivedInOntarioYears.Text)?0:Convert.ToInt32(txtLivedInOntarioYears.Text); dbEntry.LivedInOntarioMonths = string.IsNullOrEmpty(txtLivedInOntarioMonths.Text) ? 0 : Convert.ToInt32(txtLivedInOntarioMonths.Text); dbEntry.LivedInOntarioPast12Months = rdListLivedInOntarioPast12Months.SelectedIndex==-1?string.Empty : rdListLivedInOntarioPast12Months.SelectedValue; dbEntry.DOBYear = string.IsNullOrEmpty(txtDOB.Text) ? 0 : DateTime.ParseExact(txtDOB.Text, "MM/dd/yyyy", null).Year; dbEntry.DOBMonth = string.IsNullOrEmpty(txtDOB.Text) ? 0 : DateTime.ParseExact(txtDOB.Text, "MM/dd/yyyy", null).Month; dbEntry.DOBDay = string.IsNullOrEmpty(txtDOB.Text) ? 0 : DateTime.ParseExact(txtDOB.Text, "MM/dd/yyyy", null).Day; dbEntry.BirthCityTownVillage = txtBirthCityTownVillage.Text; dbEntry.BirthProvinceOrState = txtBirthProvinceOrState.Text; dbEntry.BirthCountry = txtBirthCountry.Text; dbEntry.NewFirstName = txtNewFirstName.Text; dbEntry.NewMiddleName = txtNewMiddleName.Text; dbEntry.NewLastName = txtNewLastName.Text; dbEntry.Married = rdListMarried.SelectedValue; dbEntry.PartnerFisrtName = txtPartnerFisrtName.Text; dbEntry.PartnerMiddleName = txtPartnerMiddleName.Text; dbEntry.PartnerLastName = txtPartnerLastName.Text; dbEntry.DateMarriedMonth = string.IsNullOrEmpty(txtDateMarried.Text) ? 0 : DateTime.ParseExact(txtDateMarried.Text, "MM/dd/yyyy",null).Month; dbEntry.DateMarriedDay = string.IsNullOrEmpty(txtDateMarried.Text) ? 0 : DateTime.ParseExact(txtDateMarried.Text, "MM/dd/yyyy",null).Day; dbEntry.DateMarriedYear = string.IsNullOrEmpty(txtDateMarried.Text) ? 0 : DateTime.ParseExact(txtDateMarried.Text, "MM/dd/yyyy", null).Year; dbEntry.CityTownMarried = txtCityTownMarried.Text; dbEntry.StateOrProvinceMarried = txtStateOrProvinceMarried.Text; dbEntry.CountryMarried =ddlCountryMarried.SelectedIndex==-1?string.Empty:ddlCountryMarried.SelectedValue; dbEntry.JDeclarationSigned = rdListJDeclarationSigned.SelectedIndex == -1 ? string.Empty : rdListJDeclarationSigned.SelectedValue; dbEntry.JDeclarationPersonFirstName = txtJDeclarationPersonFirstName.Text; dbEntry.JDeclarationPersonMiddleName = txtJDeclarationPersonMiddleName.Text; dbEntry.JDeclarationPersonLastName = txtJDeclarationPersonLastName.Text; dbEntry.SentRegistrarMonth = string.IsNullOrEmpty(txtSentRegistrarDate.Text) ? 0 : DateTime.ParseExact(txtSentRegistrarDate.Text, "MM/dd/yyyy", null).Month; dbEntry.SentRegistrarDay = string.IsNullOrEmpty(txtSentRegistrarDate.Text) ? 0 : Convert.ToDateTime(txtSentRegistrarDate.Text).Day; dbEntry.SentRegistrarYear = string.IsNullOrEmpty(txtSentRegistrarDate.Text) ? 0 : Convert.ToDateTime(txtSentRegistrarDate.Text).Year; dbEntry.SubmittedForm4 = rdListSubmittedForm4.SelectedIndex == -1 ? string.Empty : rdListSubmittedForm4.SelectedValue; dbEntry.EntryDate= DateTime.Today; dbEntry.EntryIP= CommonFunctions.GetIpAddress(); dbEntry.IsActive= true; dbEntry.EntryId = Convert.ToString(Session["USER_KEY"]); dataContext.Entry(dbEntry).State = EntityState.Modified; } else { var entry = new PersonalInformation { Id=id, PdfFormTemplateId = Guid.Parse(CurrentId), UserId = Convert.ToString(Session["USER_KEY"]), PresentFirstName = txtPresentFirstName.Text, PresentMiddleName = txtPresentMiddleName.Text, PresentLastName = txtPresentLastName.Text, Sex = rdListSex.SelectedIndex == -1 ? string.Empty : rdListSex.SelectedItem.Value, MailAddStreetNo = txtMailAddStreetNo.Text, MailAddPOBox = txtMailAddPOBox.Text, MailAddAptSuitNo = txtMailAddAptSuitNo.Text, MailAddBuzzerNo = txtMailAddBuzzerNo.Text, MailAddCityTownVillage = txtMailAddCityTownVillage.Text, MailAddProvience = txtMailAddProvience.Text, MailAddPostalCode = txtMailAddPostalCode.Text, MailAddHomePhoneCode = txtMailAddHomePhoneCode.Text, MailAddHomePhoneNo = txtMailAddHomePhoneNo.Text, MailAddWorkPhoneCode = txtMailAddWorkPhoneCode.Text, MailAddWorkPhoneNo = txtMailAddWorkPhoneNo.Text, LivedInOntarioYears = string.IsNullOrEmpty(txtLivedInOntarioYears.Text) ? 0 : Convert.ToInt32(txtLivedInOntarioYears.Text), LivedInOntarioMonths = string.IsNullOrEmpty(txtLivedInOntarioMonths.Text) ? 0 : Convert.ToInt32(txtLivedInOntarioMonths.Text), LivedInOntarioPast12Months = rdListLivedInOntarioPast12Months.SelectedIndex == -1 ? string.Empty : rdListLivedInOntarioPast12Months.SelectedValue, DOBYear = string.IsNullOrEmpty(txtDOB.Text) ? 0 : DateTime.ParseExact(txtDOB.Text, "MM/dd/yyyy", null).Year, DOBMonth = string.IsNullOrEmpty(txtDOB.Text) ? 0 : DateTime.ParseExact(txtDOB.Text, "MM/dd/yyyy", null).Month, DOBDay = string.IsNullOrEmpty(txtDOB.Text) ? 0 : DateTime.ParseExact(txtDOB.Text, "MM/dd/yyyy", null).Day, BirthCityTownVillage = txtBirthCityTownVillage.Text, BirthProvinceOrState = txtBirthProvinceOrState.Text, BirthCountry = txtBirthCountry.Text, NewFirstName = txtNewFirstName.Text, NewMiddleName = txtNewMiddleName.Text, NewLastName = txtNewLastName.Text, Married = rdListMarried.SelectedValue, PartnerFisrtName = txtPartnerFisrtName.Text, PartnerMiddleName = txtPartnerMiddleName.Text, PartnerLastName = txtPartnerLastName.Text, DateMarriedMonth = string.IsNullOrEmpty(txtDateMarried.Text) ? 0 : DateTime.ParseExact(txtDateMarried.Text, "MM/dd/yyyy", null).Month, DateMarriedDay = string.IsNullOrEmpty(txtDateMarried.Text) ? 0 : DateTime.ParseExact(txtDateMarried.Text, "MM/dd/yyyy", null).Day, DateMarriedYear = string.IsNullOrEmpty(txtDateMarried.Text) ? 0 : DateTime.ParseExact(txtDateMarried.Text, "MM/dd/yyyy", null).Year, CityTownMarried = txtCityTownMarried.Text, StateOrProvinceMarried = txtStateOrProvinceMarried.Text, CountryMarried = ddlCountryMarried.SelectedIndex == -1 ? string.Empty : ddlCountryMarried.SelectedValue, JDeclarationSigned = rdListJDeclarationSigned.SelectedIndex == -1 ? string.Empty : rdListJDeclarationSigned.SelectedValue, JDeclarationPersonFirstName = txtJDeclarationPersonFirstName.Text, JDeclarationPersonMiddleName = txtJDeclarationPersonMiddleName.Text, JDeclarationPersonLastName = txtJDeclarationPersonLastName.Text, SentRegistrarMonth = string.IsNullOrEmpty(txtSentRegistrarDate.Text) ? 0 : DateTime.ParseExact(txtSentRegistrarDate.Text, "MM/dd/yyyy", null).Month, SentRegistrarDay = string.IsNullOrEmpty(txtSentRegistrarDate.Text) ? 0 : Convert.ToDateTime(txtSentRegistrarDate.Text).Day, SentRegistrarYear = string.IsNullOrEmpty(txtSentRegistrarDate.Text) ? 0 : Convert.ToDateTime(txtSentRegistrarDate.Text).Year, SubmittedForm4 = rdListSubmittedForm4.SelectedIndex == -1 ? string.Empty : rdListSubmittedForm4.SelectedValue, EntryDate = DateTime.Today, EntryIP = CommonFunctions.GetIpAddress(), IsActive = true, EntryId = Convert.ToString(Session["USER_KEY"]) }; dataContext.PersonalInformations.Add(entry); } dataContext.SaveChanges(); returnMessage = "Data submitted successfully!"; } } catch (DbEntityValidationException ex) { returnMessage = ex.EntityValidationErrors.SelectMany(eve => eve.ValidationErrors).Aggregate(returnMessage, (current, ve) => current + (ve.PropertyName + " Error Msg:" + ve.ErrorMessage)); } return returnMessage; }
private string Submit() { var id = Guid.Parse(RecordId); var returnMessage = string.Empty; try { using (var dataContext = new nChangerDb()) { var dbEntry = dataContext.NameChangeInformations.Find(id); if (dbEntry != null) { dbEntry.ResonForNameChange = txtResonForNameChange.Text; dbEntry.ChangedNamePriviously = rdListChangedNamePriviously.SelectedIndex != -1 ? rdListChangedNamePriviously.SelectedValue:string.Empty; dbEntry.UserId = UserId; dbEntry.PreviousNameChangeDay = string.IsNullOrEmpty(txtPreviousNameChangeDate.Text) ? 0 : DateTime.ParseExact(txtPreviousNameChangeDate.Text, "MM/dd/yyyy", null).Day; dbEntry.PreviousNameChangeMonth = string.IsNullOrEmpty(txtPreviousNameChangeDate.Text) ? 0 : DateTime.ParseExact(txtPreviousNameChangeDate.Text, "MM/dd/yyyy", null).Month; dbEntry.PreviousNameChangeYear = string.IsNullOrEmpty(txtPreviousNameChangeDate.Text) ? 0 : DateTime.ParseExact(txtPreviousNameChangeDate.Text, "MM/dd/yyyy", null).Year; dbEntry.PreviousFirstName = txtPreviousFirstName.Text; dbEntry.PreviousMiddleName = txtPreviousMiddleName.Text; dbEntry.PreviousLastName = txtPreviousLastName.Text; dbEntry.FirstNameAfterChange = txtFirstNameAfterChange.Text; dbEntry.MiddleNameAfterChange = txtMiddleNameAfterChange.Text; dbEntry.LastNameAfterChange = txtLastNameAfterChange.Text; dbEntry.PreviousNameChangeProvince = txtPreviousNameChangeProvince.Text; dbEntry.PreviousNameChangeCountry = ddlCountry.SelectedIndex != -1 ? ddlCountry.SelectedValue:string.Empty; dbEntry.AppliedForChangeAndRefused = rdLstAppliedForChangeAndRefused.SelectedIndex == 0; dbEntry.EntryDate = DateTime.Today; dbEntry.EntryIP = CommonFunctions.GetIpAddress(); dbEntry.IsActive = true; dbEntry.EntryId = UserId; dataContext.Entry(dbEntry).State = EntityState.Modified; } else { var entry = new NameChangeInformation() { Id =id, PdfFormTemplateId = Guid.Parse(CurrentId), UserId = UserId, ResonForNameChange = txtResonForNameChange.Text, ChangedNamePriviously = rdListChangedNamePriviously.SelectedIndex != -1? rdListChangedNamePriviously.SelectedValue:string.Empty, PreviousNameChangeDay = string.IsNullOrEmpty(txtPreviousNameChangeDate.Text) ? 0 : DateTime.ParseExact(txtPreviousNameChangeDate.Text, "MM/dd/yyyy", null).Day, PreviousNameChangeMonth = string.IsNullOrEmpty(txtPreviousNameChangeDate.Text) ? 0 : DateTime.ParseExact(txtPreviousNameChangeDate.Text, "MM/dd/yyyy", null).Month, PreviousNameChangeYear = string.IsNullOrEmpty(txtPreviousNameChangeDate.Text) ? 0 : DateTime.ParseExact(txtPreviousNameChangeDate.Text, "MM/dd/yyyy", null).Year, PreviousFirstName = txtPreviousFirstName.Text, PreviousMiddleName = txtPreviousMiddleName.Text, PreviousLastName = txtPreviousLastName.Text, FirstNameAfterChange = txtFirstNameAfterChange.Text, MiddleNameAfterChange = txtMiddleNameAfterChange.Text, LastNameAfterChange = txtLastNameAfterChange.Text, PreviousNameChangeProvince = txtPreviousNameChangeProvince.Text, PreviousNameChangeCountry = ddlCountry.SelectedIndex != -1 ? ddlCountry.SelectedValue:string.Empty, AppliedForChangeAndRefused = rdLstAppliedForChangeAndRefused.SelectedIndex == 0, EntryDate = DateTime.Today, EntryIP = CommonFunctions.GetIpAddress(), IsActive = true, EntryId = UserId }; dataContext.NameChangeInformations.Add(entry); } dataContext.SaveChanges(); returnMessage = "Data submitted successfully!"; } } catch (DbEntityValidationException ex) { returnMessage = ex.EntityValidationErrors.SelectMany(eve => eve.ValidationErrors).Aggregate(returnMessage, (current, ve) => current + (ve.PropertyName + " Error Msg:" + ve.ErrorMessage)); } return returnMessage; }