public ActionResult CrearVehiculo(DataModels.Vehiculo model)
        {
            try
            {
                if (model.IdDueno == 0)
                {
                    ModelState.AddModelError(string.Empty, "Aún no hay Dueños Disponibles o no ha Elegido un Dueño para Asignar");
                }

                DataModels.ManagerVehiculos managerVehiculo = new DataModels.ManagerVehiculos();
                bool patenteExistente = managerVehiculo.PatenteExiste(model.Patente);
                if (patenteExistente)
                {
                    ModelState.AddModelError(string.Empty, "La patente que está ingresando ya existe");
                }
                if (ModelState.IsValid)
                {
                    bool result = managerVehiculo.CrearVehiculo(model);
                    if (result)
                    {
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        return(View(model));
                    }
                }
            }
            catch
            {
                return(View(model));
            }

            return(View(model));
        }
 public ActionResult DetallesVehiculo(int id)
 {
     DataModels.ManagerVehiculos managerVehiculos       = new DataModels.ManagerVehiculos();
     DataModels.Vehiculo         vehiculo               = managerVehiculos.BuscarVehiculo(id);
     Models.VehiculosDuenos      detallesVehiculosDueno = managerVehiculos.NombreDueno(vehiculo.IdVehiculo, vehiculo.IdDueno);
     return(View(detallesVehiculosDueno));
 }
 public ActionResult EliminarVehiculo(int id, DataModels.Vehiculo model)
 {
     try
     {
         DataModels.ManagerVehiculos managerVehiculo = new DataModels.ManagerVehiculos();
         bool result = managerVehiculo.EliminarVehiculo(id);
         return(RedirectToAction("Index", "Dueno"));
     }
     catch
     {
         return(View(model));
     }
 }
Beispiel #4
0
 public DataModels.Vehiculo BuscarVehiculo(int idVehiculo)
 {
     DataModels.Vehiculo vehiculo = new DataModels.Vehiculo();
     try
     {
         using (var db = new BDEvaluacionVehiculosEntities())
         {
             vehiculo = db.Vehiculo.SingleOrDefault(v => v.IdVehiculo == idVehiculo);
         }
         return(vehiculo);
     }
     catch (Exception)
     {
         return(new DataModels.Vehiculo());
     }
 }
 public ActionResult EditarVehiculo(int id, DataModels.Vehiculo model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             DataModels.ManagerVehiculos managerVehiculo = new DataModels.ManagerVehiculos();
             managerVehiculo.ActualizarVehiculo(model);
             return(RedirectToAction("Index"));
         }
     }
     catch
     {
         throw;
     }
     return(View(model));
 }
Beispiel #6
0
        public bool ActualizarVehiculo(DataModels.Vehiculo vehiculo)
        {
            try
            {
                using (var db = new DataModels.BDEvaluacionVehiculosEntities())
                {
                    if (vehiculo.Patente != null && vehiculo.IdDueno != 0)
                    {
                        db.Vehiculo.Attach(vehiculo);
                        db.Entry(vehiculo).State = System.Data.EntityState.Modified;
                        db.SaveChanges();

                        return(true);
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #7
0
 public bool CrearVehiculo(DataModels.Vehiculo vehiculo)
 {
     try
     {
         using (var db = new BDEvaluacionVehiculosEntities())
         {
             vehiculo.Patente = FormatoPatente(vehiculo.Patente);
             if (vehiculo.IdDueno != 0)
             {
                 db.Vehiculo.Add(vehiculo);
                 db.SaveChanges();
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public ActionResult CrearVehiculo()
 {
     DataModels.Vehiculo vehiculo = new DataModels.Vehiculo();
     return(View());
 }
 public ActionResult EditarVehiculo(int id)
 {
     DataModels.ManagerVehiculos managerVehiculo = new DataModels.ManagerVehiculos();
     DataModels.Vehiculo         vehiculo        = managerVehiculo.BuscarVehiculo(id);
     return(View(vehiculo));
 }