private void AddItemButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                switch (CategorySelectorComboBox.SelectedValue)
                {
                case "Brands":
                    BrandWindow brandWindow = new BrandWindow();
                    brandWindow.ShowDialog();
                    if (brandWindow.successFlag)
                    {
                        autoManager.Brand.Add(brandWindow.Brand);
                        autoManager.SaveChanges();
                    }
                    break;

                case "Car models":
                    CarModelWindow carModelWindow = new CarModelWindow(autoManager.Brand.ToList());
                    carModelWindow.ShowDialog();
                    if (carModelWindow.successFlag)
                    {
                        autoManager.Car_model.Add(carModelWindow.car_model);
                        autoManager.SaveChanges();
                    }
                    break;

                case "Offices":
                    OfficeWindow officeWindow = new OfficeWindow();
                    officeWindow.ShowDialog();
                    if (officeWindow.successFlag)
                    {
                        autoManager.Office.Add(officeWindow.office);
                        autoManager.SaveChanges();
                    }
                    break;

                case "Customers":
                    CustomerWindow customerWindow = new CustomerWindow();
                    customerWindow.ShowDialog();
                    if (customerWindow.successFlag)
                    {
                        autoManager.Customer.Add(customerWindow.customer);
                        autoManager.SaveChanges();
                    }
                    break;

                case "Employees":
                    EmployeeWindow employeeWindow = new EmployeeWindow(autoManager.Office.ToList());
                    employeeWindow.ShowDialog();
                    if (employeeWindow.successFlag)
                    {
                        autoManager.Employee.Add(employeeWindow.employee);
                        autoManager.SaveChanges();
                    }
                    break;

                case "Accidents":
                    AccidentWindow accidentWindow = new AccidentWindow(autoManager.Car.ToList());
                    accidentWindow.ShowDialog();
                    if (accidentWindow.successFlag)
                    {
                        var id = autoManager.Accident.Select(a => a.accident_id).Max() + 1;
                        accidentWindow.accident.accident_id = id;
                        autoManager.Accident.Add(accidentWindow.accident);
                        autoManager.SaveChanges();
                    }
                    break;

                case "Cars":
                    CarWindow carWindow = new CarWindow(autoManager.Car_model.ToList());
                    carWindow.ShowDialog();
                    if (carWindow.successFlag)
                    {
                        autoManager.Car.Add(carWindow.car);
                        autoManager.SaveChanges();
                    }
                    break;

                case "Lease contracts":
                    LeaseWindow leaseWindow = new LeaseWindow(autoManager.Office.ToList(), autoManager.Customer.ToList(), autoManager.Car.ToList());
                    leaseWindow.ShowDialog();
                    if (leaseWindow.successFlag)
                    {
                        autoManager.Lease_contract.Add(leaseWindow.lease_Contract);
                        autoManager.SaveChanges();
                    }
                    break;

                case "Purchase contracts":
                    PurchaseWindow purchaseWindow = new PurchaseWindow(autoManager.Office.ToList(), autoManager.Customer.ToList(), autoManager.Car.ToList());
                    purchaseWindow.ShowDialog();
                    if (purchaseWindow.successFlag)
                    {
                        autoManager.Purchase_contract.Add(purchaseWindow.purchase_Contract);
                        autoManager.SaveChanges();
                    }
                    break;
                }
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                MessageBox.Show("Error during adding item! Probably, you are trying to insert duplicate key into db", "Error");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error during adding item! " + ex.Message + " " + ex.InnerException, "Warning");
            }
            UpdateGrid();
        }
        private void EditItemButton_Click(object sender, RoutedEventArgs e)
        {
            if (MainDataGrid.SelectedItem != null)
            {
                switch (CategorySelectorComboBox.SelectedValue)
                {
                case "Brands":
                    var tbb  = autoManager.Brand.ToList()[MainDataGrid.SelectedIndex];
                    var tbbl = new List <Brand>()
                    {
                        tbb
                    };
                    BrandWindow brandWindow = new BrandWindow(tbbl);
                    brandWindow.ShowDialog();
                    if (brandWindow.successFlag)
                    {
                        tbb.price_category = brandWindow.Brand.price_category;

                        autoManager.SaveChanges();
                    }
                    break;

                case "Car models":
                    //var item = autoManager.Car_model.ToList()[MainDataGrid.SelectedIndex];
                    //var itemL = new List<Car_model>() { item };
                    //CarModelWindow carModelWindow = new CarModelWindow(itemL);
                    //carModelWindow.ShowDialog();
                    //if (carModelWindow.successFlag)
                    //{
                    //    item.brand_name = carModelWindow.brand_nameTextBox.Text;
                    //    autoManager.SaveChanges();
                    //}
                    break;

                case "Offices":
                    var office = autoManager.Office.ToList()[MainDataGrid.SelectedIndex];
                    var ofL    = new List <Office>()
                    {
                        office
                    };
                    OfficeWindow officeWindow = new OfficeWindow(ofL);
                    officeWindow.ShowDialog();
                    if (officeWindow.successFlag)
                    {
                        office.capacity = officeWindow.office.capacity;
                        autoManager.SaveChanges();
                    }
                    break;

                case "Customers":
                    var customer = autoManager.Customer.ToList()[MainDataGrid.SelectedIndex];
                    var cL       = new List <Customer>()
                    {
                        customer
                    };
                    CustomerWindow customerWindow = new CustomerWindow(cL);
                    customerWindow.ShowDialog();
                    if (customerWindow.successFlag)
                    {
                        customer.customer_address   = customerWindow.customer.customer_address;
                        customer.full_name          = customerWindow.customer.full_name;
                        customer.driving_experience = customerWindow.customer.driving_experience;
                        customer.gender             = customerWindow.customer.gender;
                        customer.phone_number       = customerWindow.customer.phone_number;
                        autoManager.SaveChanges();
                    }
                    break;

                case "Employees":
                    var emp  = autoManager.Employee.ToList()[MainDataGrid.SelectedIndex];
                    var empL = new List <Employee>()
                    {
                        emp
                    };
                    EmployeeWindow employeeWindow = new EmployeeWindow(empL, autoManager.Office.ToList());
                    employeeWindow.ShowDialog();
                    if (employeeWindow.successFlag)
                    {
                        emp.full_name      = employeeWindow.employee.full_name;
                        emp.gender         = employeeWindow.employee.gender;
                        emp.birth_date     = employeeWindow.employee.birth_date;
                        emp.office_address = employeeWindow.employee.office_address;
                        autoManager.SaveChanges();
                    }
                    break;

                case "Accidents":
                    var ac  = autoManager.Accident.ToList()[MainDataGrid.SelectedIndex];
                    var acL = new List <Accident>()
                    {
                        ac
                    };
                    AccidentWindow accidentWindow = new AccidentWindow(acL, autoManager.Car.ToList());
                    accidentWindow.ShowDialog();
                    if (accidentWindow.successFlag)
                    {
                        ac.accident_date      = accidentWindow.accident.accident_date;
                        ac.carplate_number    = accidentWindow.accident.carplate_number;
                        ac.damage             = accidentWindow.accident.damage;
                        ac.damage_description = accidentWindow.accident.damage_description;
                        autoManager.SaveChanges();
                    }
                    break;

                case "Cars":
                    var car  = autoManager.Car.ToList()[MainDataGrid.SelectedIndex];
                    var carL = new List <Car>()
                    {
                        car
                    };
                    CarWindow carWindow = new CarWindow(carL, autoManager.Car_model.ToList());
                    carWindow.ShowDialog();
                    if (carWindow.successFlag)
                    {
                        car.carplate_number = carWindow.car.carplate_number;
                        car.car_status      = carWindow.car.car_status;
                        car.color           = carWindow.car.color;
                        car.mileage         = carWindow.car.mileage;
                        car.model_name      = carWindow.car.model_name;
                        autoManager.SaveChanges();
                    }
                    break;

                case "Lease contracts":
                    //var ll = autoManager.Lease_contract.ToList()[MainDataGrid.SelectedIndex];
                    //var lll = new List<Lease_contract>() { ll };
                    //var lease_Contract = new LeaseWindow(lll);
                    //lease_Contract.ShowDialog();
                    break;

                case "Purchase contracts":
                    //var pp = autoManager.Purchase_contract.ToList()[MainDataGrid.SelectedIndex];
                    //var ppL = new List<Purchase_contract>() { pp };
                    //PurchaseWindow purchaseWindow = new PurchaseWindow(ppL);
                    //purchaseWindow.ShowDialog();
                    break;

                default:
                    throw new NotImplementedException();
                }
                UpdateGrid();
            }


            else
            {
                MessageBox.Show("Please, select one record to edit!", "Warning");
            }
        }