예제 #1
0
 private void AddCompany()
 {
     try
     {
         var dialog     = new CompanyDialog();
         var newCompany = dialog.ShowDialog(new company(), true, AvailableCompanies.ToList());
         if (newCompany != null)
         {
             if (AvailableCompanies.Any(com => com.ID == newCompany.ID ||
                                        string.Equals(com.Name, newCompany.Name)))
             {
                 MessageBox.Show("Please provide unique details", "Error!");
             }
             else
             {
                 AvailableCompanies.Add(newCompany);
                 CompanyRepo.dbSet.Add(newCompany);
                 CompanyRepo.context.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         // this is wrong
         // we cann't show a dialog from view model
         // as no logging is implemented so I am adding it here
         MessageBox.Show(ex.Message, "Error!");
     }
 }
예제 #2
0
 private void SearchForCompany()
 {
     try
     {
         var dialog     = new CompanyDialog();
         var newCompany = dialog.ShowDialog(new company(), false, AvailableCompanies.ToList());
         if (newCompany != null)
         {
             //no update
         }
     }
     catch (Exception ex)
     {
         // this is wrong
         // we cann't show a dialog from view model
         // as no logging is implemented so I am adding it here
         MessageBox.Show(ex.Message, "Error!");
     }
 }