private void Button_Click(object sender, RoutedEventArgs e) { InsuranceProduct ip = new InsuranceProduct(); try { ip.ProductId = Convert.ToInt32(txtProdId.Text); ip.Products = txtName.Text; if (btnLife.IsChecked == true) { ip.ProductType = "Life"; } else { ip.ProductType = "NonLife"; } if (ValidateProduct()) { sq.InsuranceProducts.Add(ip); sq.SaveChanges(); this.Close(); AdminAccess ad = new AdminAccess(); ad.gridProducts.DataContext = sq.InsuranceProducts.ToList(); ad.Show(); } else { MessageBox.Show("All Fields are Mandatory"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Button_Click(object sender, RoutedEventArgs e) { Endorsement end = new Endorsement(); try { DateTime dt = Convert.ToDateTime(txtDob.Text); Customer customer = sq.Customers.Where(x => x.Dob == dt).Select(x => x).FirstOrDefault(); end.CustId = customer.CustId; end.Policynumber = txtPolicyNumber.Text; InsuranceProduct product = sq.InsuranceProducts.Where(x => x.Products == txtProductName.Text).Select(x => x).FirstOrDefault(); end.ProductId = product.ProductId; end.InsuredName = txtInsuredName.Text; end.InsuredAge = Convert.ToInt32(txtAge.Text); end.Dob = Convert.ToDateTime(txtDob.Text); end.Nominee = txtNominee.Text; end.Relation = txtRelation.Text; end.Address = txtAddress.Text; end.Telephone = txtTelephone.Text; end.PremiumPaymentFrequency = txtPaymentFrequency.Text; if (btnMale.IsChecked == true) { end.Gender = "Male"; } else { end.Gender = "Female"; } if (btnSmoker.IsChecked == true) { end.Smoker = "Smoker"; } else { end.Smoker = "NonSmoker"; } sq.Endorsements.Add(end); sq.SaveChanges(); } catch (Exception) { throw; } MessageBox.Show("Request Sent"); }