public void Insert(Driver driver)
        {
            Driver newDriver = new Driver();
            newDriver.Name = driver.Name;
            newDriver.Surname = driver.Surname;
            newDriver.MiddleName = driver.MiddleName;
            newDriver.Phone = driver.Phone;
            newDriver.Login = driver.Login;
            newDriver.Password = driver.Password;
            newDriver.LicenseNum = driver.LicenseNum;
            newDriver.LicenseValidDate = driver.LicenseValidDate;
            newDriver.Nationality = driver.Nationality;
            newDriver.Car = driver.Car;

            context.Entry<Driver>(newDriver).State = System.Data.Entity.EntityState.Added;

            try
            {
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                var e = ex;
            }
        }
 public void Delete(Driver driver)
 {
     var delDriver = context.Driver.Include("Car").First(d => d.Id == driver.Id);
     var delCar = context.Car.First(c => c.Id == delDriver.Car.Id);
     context.Car.Remove(delCar);
     context.Driver.Remove(delDriver);
     context.SaveChanges();
 }
        public DriverProfileModel GetDriverModel(Driver driver , List<History> history)
        {
            DriverProfileModel dpm = new DriverProfileModel
            {
                Id = driver.Id,
                Name = driver.Name,
                Surname = driver.Surname,
                Middlename = driver.MiddleName,
                Phone = driver.Phone,
                Login = driver.Login,
                LicenseNumber = driver.LicenseNum,
                LicenseValidDate = driver.LicenseValidDate,
                CarBrand = driver.Car.CarBrand,
                CarModel = driver.Car.CarModel,
                CarClass = driver.Car.CarClass,
                CarNumber = driver.Car.CarNumber,
                VehicleType = driver.Car.VehicleType,
                History = history

            };
            return dpm;
        }
        private Driver GetDriver(DriverRegistrationModel model)
        {
            Car car = new Car {
                CarBrand = model.CarBrand,
                CarModel = model.CarModel,
                VehicleType = model.VehicleType,
                CarNumber = model.CarNumber,
                CarClass = model.CarClass
                };
            Driver driver = new Driver {
                Name = model.Name,
                Surname = model.Surname,
                MiddleName = model.Middlename,
                Phone = model.Phone,
                Login = model.Login,
                Password = model.Password,
                LicenseNum = model.LicenseNumber,
                LicenseValidDate = model.LicenseValidDate,
                Nationality = model.Nationality,
                Car = car
            };

            return driver;
        }
        //public void Insert(string Name , string Surname ,string MiddleName , string Phone ,Nationality Nationality,string Login , string Password )
        //{
        //    Driver newDriver = new Driver();
        //    newDriver.Name = Name;
        //    newDriver.Surname = Surname;
        //    newDriver.MiddleName = MiddleName;
        //    newDriver.Phone = Phone;
        //    newDriver.Login = Login;
        //    newDriver.Password = Password;
        //    //newDriver.LicenseNum = LicenseNum;
        //    //newDriver.LicenseValidDate = LicenseValidDate;
        //    newDriver.Nationality = Nationality;
        //
        //    context.Entry<Driver>(newDriver).State = System.Data.Entity.EntityState.Added;
        //
        //    context.SaveChanges();
        //
        //}
        public void Update(Driver driver)
        {
            var newDriver = context.Driver.Include("Car").First(d => d.Id == driver.Id);

            newDriver.Name = driver.Name;
            newDriver.Surname = driver.Surname;
            newDriver.MiddleName = driver.MiddleName;
            newDriver.Phone = driver.Phone;
            newDriver.Login = driver.Login;
            newDriver.Password = driver.Password;
            newDriver.Nationality = driver.Nationality;
            newDriver.LicenseNum = driver.LicenseNum;
            newDriver.LicenseValidDate = driver.LicenseValidDate;
            newDriver.Car = driver.Car;

            context.Entry<Driver>(newDriver).State = System.Data.Entity.EntityState.Modified;
            context.SaveChanges();
        }
 public DriverWorkModel(Driver driver, Status status, Region region)
 {
     this.Driver = driver;
     this.Status = status;
     this.Region = region;
 }