public ActionResult Create(Automovil automovil) { if (ModelState.IsValid) { if (automovil.AutomovilImagenes != null && automovil.AutomovilImagenes.Any()) { var guardarImagen = new GuardarImagen(); foreach (var imagen in automovil.AutomovilImagenes) { string fileName = Guid.NewGuid().ToString(); imagen.UrlImagenMiniatura = guardarImagen.ResizeAndSave(fileName, imagen.ImagenSubida.InputStream, Tamanos.Miniatura, false); imagen.UrlImagenMediana = guardarImagen.ResizeAndSave(fileName, imagen.ImagenSubida.InputStream, Tamanos.Miniatura, false); } } db.Automovils.Add(automovil); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ModeloId = new SelectList(db.Modelos, "ModeloId", "Descripcion", automovil.ModelosId); return(View(automovil)); }
public ActionResult Agregar(ProductosDTO ProductosDTO) { if (ModelState.IsValid) { var guardarimagen = new GuardarImagen(); if (ProductosDTO.ListaImagenes == null) { _productos.AgregarImagenPredeterminada(ProductosDTO); } else { foreach (var imagen in ProductosDTO.ListaImagenes) { string fileName = Guid.NewGuid().ToString(); imagen.UrlImagenChica = guardarimagen.ResizeAndSave(fileName, imagen.ImagenSubida.InputStream, Tamanos.Miniatura, false); imagen.UrlImagenGrande = guardarimagen.ResizeAndSave(fileName, imagen.ImagenSubida.InputStream, Tamanos.Mediana, false); } } _productos.AgregarProductos(ProductosDTO); return(RedirectToAction("Index")); } return(View()); }
public ActionResult Create(Marcas marcas) { if (ModelState.IsValid) { var guardarImagen = new GuardarImagen(); string fileName = Guid.NewGuid().ToString(); marcas.UrlImagen = guardarImagen.ResizeAndSave(fileName, marcas.ImagenSubida.InputStream, Tamanos.Miniatura, false); db.Marcas.Add(marcas); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(marcas)); }