public ActionResult GuardarVehiculo(Vehiculo vehiculo)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new VehiculoViewModel(vehiculo)
                {
                    Clientes     = _context.Clientes.ToList(),
                    Aseguradoras = _context.Aseguradoras.ToList(),
                    Modelos      = _context.Modelos.ToList(),
                    Combustibles = _context.Combustibles.ToList()
                };

                return(View("VehiculoFormulario", viewModel));
            }

            if (vehiculo.Id == 0)
            {
                vehiculo.FechaDeIngreso = DateTime.Now;
                _context.Vehiculos.Add(vehiculo);
            }
            else
            {
                var vehiculosBD = _context.Vehiculos.Single(c => c.Id == vehiculo.Id);
                Mapper.Map <Vehiculo, Vehiculo>(vehiculo, vehiculosBD);
            }

            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
예제 #2
0
        public IActionResult CrearVehiculo()
        {
            var model = new VehiculoViewModel
            {
                Marca = _comboHelper.GetComboModeloVehiculo(),
                Tipo  = _comboHelper.GetComboTipoVehiculo()
            };

            return(View(model));
        }
예제 #3
0
        public IActionResult CrearVehiculo()
        {
            var model = new VehiculoViewModel
            {
                Marca   = _comboHelper.GetComboMarcaVehiculo(),
                Tipo    = _comboHelper.GetComboTipoVehiculo(),
                Modelo  = _comboHelper.GetComboModeloVehiculo(),
                Estatus = _comboHelper.GetComboCaracteristicaVehiculo()
            };

            return(View(model));
        }
예제 #4
0
        async void Delete()
        {
            var response = await dialogService.ShowConfirm(
                "Confirmar",
                string.Format("¿Estás seguro de borrar el registro {0} {1}?", this.Marca, this.Modelo));

            if (!response)
            {
                return;
            }

            await VehiculoViewModel.GetInstance().Delete(this);
        }
예제 #5
0
 public async Task <Vehiculostbl> ToVehiculoAsync(VehiculoViewModel model, string path, bool IsNew)
 {
     return(new Vehiculostbl
     {
         Veh_Codigo = model.Veh_Codigo,
         Veh_Placa = model.Veh_Placa,
         Veh_Born = model.Veh_Born,
         Id = IsNew ? 0 : model.Id,
         ImageUrl = path,
         Veh_Estado = 'A',
         Propietario = await _dataContext1.Propietariostbls.FindAsync(model.PropietarioId),
         Veh_Detalles = model.Veh_Detalles
     });
 }
예제 #6
0
        public async Task <IActionResult> CrearVehiculo(VehiculoViewModel vehiculo)
        {
            try
            {
                if (ModelState.IsValid)
                {
                }
            }
            catch (Exception ex)
            {
            }

            return(View());
        }
예제 #7
0
        public JsonResult GuardarVehiculoInDatabase(VehiculoViewModel model)
        {
            var result = false;

            try
            {
                vehiculo ve    = db.vehiculo.Where(x => x.patente == model.patente).SingleOrDefault();
                string   value = string.Empty;
                if (ve != null)
                {
                    vehiculo veh = db.vehiculo.SingleOrDefault(s => s.patente == model.patente);

                    veh.patente           = model.patente;
                    veh.marca             = model.marca;
                    veh.modelo            = model.modelo;
                    veh.color             = model.color;
                    veh.velocidadPromedio = model.velocidadPromedio;
                    veh.rendimiento       = model.rendimiento;
                    veh.capacidadCarga    = model.capacidadCarga;
                    veh.descripcion       = model.descripcion;
                    veh.activo            = true;
                    db.SaveChanges();
                    result = true;
                }
                else
                {
                    vehiculo veh = new vehiculo();
                    veh.patente           = model.patente;
                    veh.marca             = model.marca;
                    veh.modelo            = model.modelo;
                    veh.color             = model.color;
                    veh.velocidadPromedio = model.velocidadPromedio;
                    veh.rendimiento       = model.rendimiento;
                    veh.capacidadCarga    = model.capacidadCarga;
                    veh.descripcion       = model.descripcion;
                    veh.activo            = true;
                    db.vehiculo.Add(veh);
                    db.SaveChanges();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult NuevoVehiculo()
        {
            var clientes     = _context.Clientes.ToList();
            var aseguradoras = _context.Aseguradoras.ToList();
            var modelos      = _context.Modelos.ToList();
            var combustibles = _context.Combustibles.ToList();

            var viewModel = new VehiculoViewModel()
            {
                Clientes     = clientes,
                Aseguradoras = aseguradoras,
                Modelos      = modelos,
                Combustibles = combustibles
            };

            return(View("VehiculoFormulario", viewModel));
        }
예제 #9
0
 public async Task <Vehiculo> ToVehiculo(VehiculoViewModel model, string path)
 {
     return(new Vehiculo
     {
         ModeloVehiculos = await _dataContext.ModeloVehiculos.FindAsync(model.ModeloId),
         TiposVehiculos = await _dataContext.TiposVehiculos.FindAsync(model.TipoVehiculoId),
         MarcaVehiculos = await _dataContext.MarcaVehiculos.FindAsync(model.MarcaId),
         //VehiculoCaracteristicas =
         VehiculoCaracteristicas = await _dataContext.VehiculoCaracteristicas.FindAsync(model.EstatusId),
         NombreVehiculo = model.NombreVehiculo,
         Color = model.Color,
         Kilometraje = model.Kilometraje,
         NoPlaca = model.NoPlaca,
         No_Chasis = model.No_Chasis,
         Anio_Vehiculo = model.Anio_Vehiculo,
         ImagenUrl = path,
         Precio = model.Precio
     });
 }
        public ActionResult EditarVehiculo(int id)
        {
            var vehiculo = _context.Vehiculos.SingleOrDefault(c => c.Id == id);

            if (vehiculo == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new VehiculoViewModel(vehiculo)
            {
                Clientes     = _context.Clientes.ToList(),
                Aseguradoras = _context.Aseguradoras.ToList(),
                Modelos      = _context.Modelos.ToList(),
                Combustibles = _context.Combustibles.ToList()
            };

            return(View("VehiculoFormulario", viewModel));
        }
예제 #11
0
        public ActionResult GuardarVehiculo(Vehiculo vehiculo)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new VehiculoViewModel(vehiculo)
                {
                    Clientes     = _context.Clientes.ToList(),
                    Aseguradoras = _context.Aseguradoras.ToList(),
                    Modelos      = _context.Modelos.Include(m => m.Marca).ToList(),
                    Combustibles = _context.Combustibles.ToList()
                };

                return(View("VehiculoFormulario", viewModel));
            }

            if (vehiculo.AseguradoraCodigo > 0)
            {
                var aseguradora = _context.Aseguradoras.Find(vehiculo.AseguradoraCodigo);
                _context.Aseguradoras.Attach(aseguradora);
                vehiculo.Aseguradora = aseguradora;
            }

            if (vehiculo.Id == 0)
            {
                vehiculo.FechaDeIngreso     = DateTime.Now;
                vehiculo.FechaDeFabricacion = Convert.ToDateTime(vehiculo.Fecha);
                _context.Vehiculos.Add(vehiculo);
            }
            else
            {
                var vehiculosBD = _context.Vehiculos
                                  .Include(v => v.Aseguradora)
                                  .Single(c => c.Id == vehiculo.Id);

                Mapper.Map <Vehiculo, Vehiculo>(vehiculo, vehiculosBD);
                vehiculosBD.FechaDeFabricacion = Convert.ToDateTime(vehiculo.Fecha);
                vehiculosBD.Aseguradora        = vehiculo.Aseguradora;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
예제 #12
0
        public ActionResult NuevoVehiculo()
        {
            var clientes     = _context.Clientes.ToList();
            var aseguradoras = _context.Aseguradoras.ToList();
            var modelos      = _context.Modelos.Include(m => m.Marca).ToList();
            var combustibles = _context.Combustibles.ToList();
            var tiposMotores = _context.TiposMotores.ToList();
            var cilindradas  = _context.Cilindradas.ToList();

            var viewModel = new VehiculoViewModel()
            {
                Clientes     = clientes,
                Aseguradoras = aseguradoras,
                Modelos      = modelos,
                Combustibles = combustibles
            };

            return(View("VehiculoFormulario", viewModel));
        }
예제 #13
0
        public async Task <IActionResult> EditVehiculo(VehiculoViewModel model)
        {
            if (ModelState.IsValid)
            {
                var path = model.ImageUrl;

                if (model.ImageFile != null)
                {
                    path = await _imageHelper.UploadImageAsync(model.ImageFile);
                }

                var vehiculo = await _converterHelper.ToVehiculoAsync(model, path, false);

                _context.Vehiculostbls.Update(vehiculo);
                await _context.SaveChangesAsync();

                return(RedirectToAction($"Details/{model.PropietarioId}"));
            }

            return(View(model));
        }
예제 #14
0
        public async Task <IActionResult> AddVehiculo(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var propietario = await _context.Propietariostbls.FindAsync(id.Value);

            if (propietario == null)
            {
                return(NotFound());
            }

            var model = new VehiculoViewModel
            {
                Veh_Born      = DateTime.Today,
                Veh_Estado    = 'A',
                PropietarioId = propietario.Id,
            };

            return(View(model));
        }
예제 #15
0
        public async Task <IActionResult> CrearVehiculo(VehiculoViewModel vehiculo)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var path = string.Empty;

                    if (vehiculo.ImagenFile != null)
                    {
                        var guid = Guid.NewGuid().ToString();
                        var file = $"{guid}.jpg";
                        path = Path.Combine(
                            Directory.GetCurrentDirectory(),
                            "wwwroot\\images",
                            file);

                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            await vehiculo.ImagenFile.CopyToAsync(stream);
                        }
                        path = $"~/images/{file}";
                    }

                    var v = await _convertHelper.ToVehiculo(vehiculo, path);

                    _dataContext.Vehiculos.Add(v);
                    await _dataContext.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
            }

            return(View());
        }
예제 #16
0
        public async Task <IActionResult> AddVehiculo(VehiculoViewModel model)
        {
            if (ModelState.IsValid)
            {
                var path = string.Empty;

                if (model.ImageFile != null)
                {
                    path = await _imageHelper.UploadImageAsync(model.ImageFile);
                }


                try
                {
                    var vehiculo = await _converterHelper.ToVehiculoAsync(model, path, true);

                    _context.Vehiculostbls.Add(vehiculo);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction($"Details/{model.PropietarioId}"));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException.Message.Contains("duplicate"))
                    {
                        ModelState.AddModelError(string.Empty, "Ya existe ese numero de tag");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.InnerException.Message);
                    }
                }
            }

            return(View(model));
        }
예제 #17
0
        public IHttpActionResult NuevoTipo(VehiculoViewModel model)
        {
            _repositorio.Insert(model);

            return Created("ApiVehiculos", model);
        }
예제 #18
0
        public IHttpActionResult NuevoTipo(VehiculoViewModel model)
        {
            _repositorio.Insert(model);

            return(Created("ApiVehiculos", model));
        }