Exemple #1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     using (DealershipManagerEntities context = new DealershipManagerEntities())
     {
         if (currentInsuranceBroker != null)
         {
             //It exists, find it, and edit it.
             InsuranceBroker insuranceBroker = (from insBroker in context.InsuranceBrokers
                                                where insBroker.BrokerId == currentInsuranceBroker.BrokerId
                                                select insBroker).FirstOrDefault();
             updateInsuranceBroker(insuranceBroker);
             context.SaveChanges();
             context.Connection.Close();
         }
         else
         {
             InsuranceBroker insuranceBroker = new InsuranceBroker();
             updateInsuranceBroker(insuranceBroker);
             context.InsuranceBrokers.AddObject(insuranceBroker);
             context.SaveChanges();
             context.Connection.Close();
         }
     }
     MessageBox.Show("Insurance Broker has been saved");
     customerForm.insuranceBrokerTableAdapter.Fill(customerForm.dealershipManagerDataSet.InsuranceBroker);
     customerForm.cboInsuranceBroker.SelectedItem = currentInsuranceBroker;
     customerForm.currentInsuranceBroker          = currentInsuranceBroker;
     customerForm.BindInsuranceBrokerToForm();
     this.Close();
 }