public bool Update(UnidadVehicular obj)
        {
            using (dbTransporteDRContext db = new dbTransporteDRContext())
            {
                var obj_db = db.UnidadVehicular.FirstOrDefault(x => x.Placa == obj.Placa);

                if (obj_db is null)
                {
                    throw new Exception(ExceptionMessageManager.ExceptionMessageVehiculo.DoesNotExist(obj.Placa));
                }

                if (!String.IsNullOrWhiteSpace(obj.Marca))
                {
                    obj_db.Marca = obj.Marca;
                }

                if (!String.IsNullOrWhiteSpace(obj.SerieChasis))
                {
                    obj_db.SerieChasis = obj.SerieChasis;
                }

                if (!String.IsNullOrWhiteSpace(obj.YFabricacion.ToString()))
                {
                    obj_db.YFabricacion = obj.YFabricacion;
                }


                db.SaveChanges();

                return(true);
            }
        }
        public RegistrarUnidadVehicularView(bool isUpdate = false, UnidadVehicular obj = null)
        {
            InitializeComponent();

            this.isUpdate = isUpdate;

            if (!isUpdate)
            {
                newUnidadVehicular = new UnidadVehicular();
            }
            else
            {
                TextBox_Placa.IsEnabled = false;

                newUnidadVehicular          = obj;
                copyUnidadVehicular_Updated = new UnidadVehicular();

                CopyInstance(newUnidadVehicular, copyUnidadVehicular_Updated);
                //ButtonState = "Actualizar";*/
            }

            this.DataContext = newUnidadVehicular;
            //ComboBox_Ciudades.ItemsSource = ciudades;
            //this.isUpdate = isUpdate;
        }
 private void CopyInstance(UnidadVehicular fuente, UnidadVehicular destino)
 {
     destino.Marca        = fuente.Marca;
     destino.Placa        = fuente.Placa;
     destino.SerieChasis  = fuente.SerieChasis;
     destino.YFabricacion = fuente.YFabricacion;
 }
        public bool Insert(UnidadVehicular obj)
        {
            using (dbTransporteDRContext db = new dbTransporteDRContext())
            {
                var Historiales = obj.Historial.ToList();
                obj.Historial = null;

                db.UnidadVehicular.Add(obj);

                db.SaveChanges();

                obj.Historial = Historiales;

                return(true);
            }
        }
 public bool Actualizar(UnidadVehicular obj)
 {
     if (!String.IsNullOrWhiteSpace(obj.Placa))           //EVALUO CAMPOS OBLIGATORIOS
     {
         if (unidadVehicularRepository.Exists(obj.Placa)) //EVALUO SI YA EXISTE
         {
             return(unidadVehicularRepository.Update(obj));
         }
         else
         {
             throw new Exception(ExceptionMessageManager.ExceptionMessageVehiculo.DoesNotExist(obj.Placa));
         }
     }
     else
     {
         throw new Exception(ExceptionMessageManager.ExceptionMessageVehiculo.KeyIsNull());
     }
 }
        public RegistrarHistorialView(bool isUpdate = false, Historial obj = null, IEnumerable <Conductor> listaConductores = null, IEnumerable <UnidadVehicular> listaVehiculos = null)
        {
            InitializeComponent();

            this.ComboBox_Conductor.ItemsSource       = listaConductores;
            this.ComboBox_Conductor.DisplayMemberPath = "DniNavigation.FullName";
            this.ComboBox_Vehiculo.ItemsSource        = listaVehiculos;
            this.ComboBox_Vehiculo.DisplayMemberPath  = "FullName";


            this.isUpdate = isUpdate;

            if (!isUpdate)
            {
                newHistorial = new Historial();
            }
            else
            {
                newHistorial          = obj;
                copyHistorial_Updated = new Historial();

                conductorSelected = listaConductores?.ToList().Find(x => x.Dni == newHistorial.DniConductorNavigation.Dni);
                VehiculoSelected  = listaVehiculos?.ToList().Find(x => x.Placa == newHistorial.IdUnidadNavigation?.Placa);
                CopyInstance(newHistorial, copyHistorial_Updated);
                //ButtonState = "Actualizar";*/
            }

            this.DataContext = newHistorial;


            if (!(conductorSelected is null))
            {
                this.ComboBox_Conductor.SelectedItem = conductorSelected;
            }

            if (!(VehiculoSelected is null))
            {
                this.ComboBox_Vehiculo.SelectedItem = VehiculoSelected;
            }

            //ComboBox_Ciudades.ItemsSource = ciudades;
            //this.isUpdate = isUpdate;
        }
        public bool Registrar(UnidadVehicular obj)
        {
            if (!String.IsNullOrWhiteSpace(obj.Placa))            //EVALUO CAMPOS OBLIGATORIOS
            {
                if (!unidadVehicularRepository.Exists(obj.Placa)) //EVALUO SI YA EXISTE
                {
                    //Primero verifico si se agrego de manera correcta a la DB, luego lo agrego a la Lista in Memory
                    var Result = unidadVehicularRepository.Insert(obj);

                    return(Result);
                }
                else
                {
                    throw new Exception(ExceptionMessageManager.ExceptionMessageVehiculo.AlreadyExists(obj.Placa));
                }
            }
            else
            {
                throw new Exception(ExceptionMessageManager.ExceptionMessageVehiculo.KeyIsNull());
            }
        }
 public void ToDefaultUnidadVehicular(UnidadVehicular UnidadVehicular)
 {
     CopyInstance(copyUnidadVehicular_Updated, UnidadVehicular);
 }
 private void ComboBox_Vehiculo_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     VehiculoSelected      = ComboBox_Vehiculo.SelectedItem as UnidadVehicular;
     newHistorial.IdUnidad = VehiculoSelected.Placa;
 }