Beispiel #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!");
     }
 }
Beispiel #2
0
        private void AddTransport()
        {
            try
            {
                var dialog       = new TransportDialog();
                var newTransport = dialog.ShowDialog(new transport(), true,
                                                     AvailableCompanies.ToList(), AllTransports.ToList());
                if (newTransport != null)
                {
                    if (AllTransports.Any(com => com.ID == newTransport.ID))
                    {
                        MessageBox.Show("Please provide unique details", "Error!");
                    }
                    else if (!newTransport.transport_date.HasValue || newTransport.transport_date == default(DateTime))
                    {
                        MessageBox.Show("Please provide all details for transport",
                                        "Error!");
                    }
                    else if (newTransport.transport_company_id == 0 || (newTransport.shipper_company_id == 0) || newTransport.shipper_company_id == newTransport.transport_company_id)
                    {
                        MessageBox.Show("New transport entry is having same shipper company and transport company",
                                        "Error!");
                    }
                    else
                    {
                        var shipperCompany   = AvailableCompanies.FirstOrDefault(x => x.ID == newTransport.shipper_company_id.GetValueOrDefault());
                        var transportCompany = AvailableCompanies.FirstOrDefault(x => x.ID == newTransport.transport_company_id.GetValueOrDefault());

                        var newItem = new TransportViewModel(newTransport)
                        {
                            ShipperCompanyName   = shipperCompany == null ? "" : shipperCompany.Name,
                            TransportCompanyName = transportCompany == null ? "" : transportCompany.Name
                        };
                        AllTransports.Add(newItem);

                        TransportRepo.dbSet.Add(newTransport);
                        TransportRepo.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!");
            }
        }
Beispiel #3
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!");
     }
 }