示例#1
0
        public int InsertarVehiculo(VehiculoETL vehiculo)
        {
            try
            {
                if (vehiculo != null)
                {
                    Vehiculo nuevoVehiculo = new Vehiculo()
                    {
                        Placa = vehiculo.Placa.Trim(),
                        Dueno = vehiculo.Dueno.Trim(),
                        Marca = vehiculo.Marca.Trim()
                    };

                    _dataContext.Vehiculos.Add(nuevoVehiculo);

                    if (_dataContext.Entry(nuevoVehiculo).State.Equals(EntityState.Added))
                    {
                        _dataContext.SaveChanges();

                        if (_dataContext.Entry(nuevoVehiculo).State.Equals(EntityState.Unchanged))
                        {
                            return(nuevoVehiculo.IdVehiculo);
                        }
                    }
                }

                return(0);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#2
0
        public bool ActualizarVehiculo(VehiculoETL vehiculo)
        {
            try
            {
                if (vehiculo != null && _dataContext.Vehiculos.Any(v => v.IdVehiculo == vehiculo.IdVehiculo))
                {
                    Vehiculo vehiculoActualizado = new Vehiculo()
                    {
                        IdVehiculo = vehiculo.IdVehiculo,
                        Placa      = vehiculo.Placa.Trim(),
                        Dueno      = vehiculo.Dueno.Trim(),
                        Marca      = vehiculo.Marca.Trim()
                    };

                    _dataContext.Vehiculos.Update(vehiculoActualizado);
                    _dataContext.SaveChanges();

                    if (_dataContext.Entry(vehiculoActualizado).State.Equals(EntityState.Unchanged))
                    {
                        return(true);
                    }
                }

                return(false);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public IActionResult Create2(int?id)
        {
            VehiculoETL vehiculo = _vehiculoBLL.ConsultarVehiculo((int)id);

            ViewData["Vehiculo"]   = vehiculo;
            ViewData["IdServicio"] = new SelectList(_servicioBLL.ObtenerListaDeServicios((int)id), "IdServicio", "Descripcion");
            return(View());
        }
示例#4
0
 public IActionResult Create([Bind("IdVehiculo,Placa,Dueno,Marca")] VehiculoETL vehiculo)
 {
     if (ModelState.IsValid)
     {
         int vehiculoId = _vehiculoBLL.InsertarVehiculo(vehiculo);
         return(RedirectToAction("Create2", "vehiculoServicios", new { id = vehiculoId }));
     }
     return(View(vehiculo));
 }
示例#5
0
 public bool ActualizarVehiculo(VehiculoETL vehiculo)
 {
     try
     {
         return(_vehiculoDAL.ActualizarVehiculo(vehiculo));
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#6
0
 public int InsertarVehiculo(VehiculoETL vehiculo)
 {
     try
     {
         return(_vehiculoDAL.InsertarVehiculo(vehiculo));
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#7
0
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            VehiculoETL vehiculo = _vehiculoBLL.ConsultarVehiculo((int)id);

            if (vehiculo == null)
            {
                return(NotFound());
            }
            return(View(vehiculo));
        }
示例#8
0
        public VehiculoETL ConsultarVehiculo(int idVehiculo)
        {
            try
            {
                VehiculoETL vehiculo = _dataContext.Vehiculos
                                       .Select(fila => new VehiculoETL
                {
                    IdVehiculo = fila.IdVehiculo,
                    Placa      = fila.Placa,
                    Dueno      = fila.Dueno,
                    Marca      = fila.Marca
                }).FirstOrDefault(v => v.IdVehiculo == idVehiculo);

                return(vehiculo);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#9
0
        public IActionResult Edit(int id, [Bind("IdVehiculo,Placa,Dueno,Marca")] VehiculoETL vehiculo)
        {
            if (id != vehiculo.IdVehiculo)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _vehiculoBLL.ActualizarVehiculo(vehiculo);
                }
                catch (Exception)
                {
                    throw;
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vehiculo));
        }