void DeleteTransport(Driver driver, Transport transport)
 {
     if (driver != null && transport != null)
     {
         driver = DriversTransports.Where(d => d.Id.Equals(driver.Id)).FirstOrDefault();
         if (driver != null)
         {
             transport = driver.Transports.Where(t => (t.Customer.Id.Equals(transport.Customer.Id) && t.Customer.Hour.EntryTime.Equals(transport.Customer.Hour.EntryTime) && t.Customer.Hour.ExitTime.Equals(transport.Customer.Hour.ExitTime))).FirstOrDefault();
             driver.Transports.Remove(transport);
             if (driver.Transports.Count == 0)
             {
                 DriversTransports.Remove(driver);
             }
         }
     }
 }
        public void AddExitTransport(Driver driver, Customer customer)
        {
            if (driver != null && customer != null && !_isDriverDeleting && TransportRowSelected != null && TransportRowSelected.Transport != null)
            {
                Transport transport = new Transport()
                {
                    Customer = customer, EntryDriver = TransportRowSelected.EntryDriver, ExitDriver = TransportRowSelected.ExitDriver, IsCanceled = !TransportRowSelected.IsCanceled
                };

                if (Context.UpdateTransport(transport))
                {
                    if (transport.EntryDriver == null)
                    {
                        IncompletedCount++;
                    }
                    else
                    {
                        IncompletedCount--;
                    }

                    if (DriversTransports.Contains(driver))
                    {
                        Transport tr = driver.Transports.Where(t => (t.Customer.Hour.EntryTime.Equals(customer.Hour.EntryTime) && t.Customer.Hour.ExitTime.Equals(customer.Hour.ExitTime))).FirstOrDefault();
                        if (tr != null)
                        {
                            if (tr.ExitDriver == null)
                            {
                                tr.ExitDriver = driver;
                                foreach (Driver dr in DriversTransports.Where(d => (!d.Id.Equals(driver.Id))).ToList())
                                {
                                    Transport td = dr.Transports.Where(t => (t.Customer.Hour.EntryTime.Equals(customer.Hour.EntryTime) && t.Customer.Hour.ExitTime.Equals(customer.Hour.ExitTime))).FirstOrDefault();
                                    if (td != null)
                                    {
                                        if (td.EntryDriver == null)
                                        {
                                            dr.Transports.Remove(td);
                                            if (dr.Transports.Count == 0)
                                            {
                                                DriversTransports.Remove(dr);
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                Driver dr = DriversTransports.Where(d => d.Id.Equals(tr.EntryDriver.Id)).FirstOrDefault();
                                if (tr.EntryDriver != null)
                                {
                                    if (!tr.ExitDriver.Id.Equals(tr.EntryDriver.Id))
                                    {
                                        Transport td = dr.Transports.Where(t => (t.Customer.Hour.EntryTime.Equals(customer.Hour.EntryTime) && t.Customer.Hour.ExitTime.Equals(customer.Hour.ExitTime))).FirstOrDefault();
                                        if (td != null)
                                        {
                                            td.ExitDriver = null;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            transport.EntryDriver = null;
                            driver.AddTransport(transport);
                            foreach (Driver dr in DriversTransports.Where(d => (!d.Id.Equals(driver.Id))).ToList())
                            {
                                Transport td = dr.Transports.Where(t => (t.Customer.Hour.EntryTime.Equals(customer.Hour.EntryTime) && t.Customer.Hour.ExitTime.Equals(customer.Hour.ExitTime))).FirstOrDefault();
                                if (td != null)
                                {
                                    if (td.EntryDriver == null)
                                    {
                                        dr.Transports.Remove(td);
                                        if (dr.Transports.Count == 0)
                                        {
                                            DriversTransports.Remove(dr);
                                        }
                                    }
                                    else
                                    {
                                        td.ExitDriver = null;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (Driver dr in DriversTransports)
                        {
                            transport = dr.Transports.Where(t => (t.Customer.Id.Equals(customer.Id) && t.Customer.Hour.EntryTime.Equals(customer.Hour.EntryTime))).FirstOrDefault();
                            if (transport != null)
                            {
                                if (transport.EntryDriver == null && transport.ExitDriver != null)
                                {
                                    dr.Transports.Remove(transport);
                                    if (dr.Transports.Count == 0)
                                    {
                                        DriversTransports.Remove(dr);
                                        break;
                                    }
                                }
                                else
                                {
                                    transport.ExitDriver = null;
                                }
                            }
                        }

                        transport = new Transport()
                        {
                            Customer = customer, ExitDriver = driver
                        };
                        driver.AddTransport(transport);
                        DriversTransports.Add(driver);
                    }
                }
            }
            _isDriverDeleting = false;
        }