/*METODO PARA EXTRAER Y CONVERTIR LA SECUENCIA DE BYTES EN IMAGEN*/ public ActionResult getImage(int id) { if (Session["User"] != null) { ViewBag.Nombre = Session["FirstName"]; ViewBag.Apellido = Session["LastName"]; TB_IMAGENES persona = db.TB_IMAGENES.Find(id); string byteImage = persona.url_imagen; //convertir MemoryStream memoryStream = new MemoryStream(Convert.ToInt32(byteImage)); Image image = Image.FromStream(memoryStream); memoryStream = new MemoryStream(); image.Save(memoryStream, ImageFormat.Jpeg); memoryStream.Position = 0; return(File(memoryStream, "imagen/jpg")); } else { return(RedirectToAction("ListarImagenes")); } }
/*DETAILS*/ public ActionResult DetailsImagen(int?id) { if (Session["User"] != null) { ViewBag.Nombre = Session["FirstName"]; ViewBag.Apellido = Session["LastName"]; TB_IMAGENES persona = db.TB_IMAGENES.Find(id); return(View(persona)); } else { return(RedirectToAction("ListarImagenes")); } }
public ActionResult EditImagen(TB_IMAGENES obj) { if (Session["User"] != null) { ViewBag.Nombre = Session["FirstName"]; ViewBag.Apellido = Session["LastName"]; //byte[] imagenActual = null TB_IMAGENES _persona = new TB_IMAGENES(); HttpPostedFileBase archivoBase = Request.Files[0]; //me quedo con la imagen que tengo if (archivoBase.ContentLength == 0) { _persona = db.TB_IMAGENES.Find(obj.cod_imagen); obj.url_imagen = _persona.url_imagen; } else { if (archivoBase.FileName.EndsWith(".jpg")) { WebImage image = new WebImage(archivoBase.InputStream); obj.url_imagen = image.ToString(); } else { ModelState.AddModelError("foto", "Solo se permite imagenes con formato JPG.... "); return(View(db.TB_IMAGENES.Find(obj.cod_imagen))); } } if (ModelState.IsValid) { db.Entry(_persona).State = System.Data.Entity.EntityState.Detached; db.Entry(obj).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("ListarImagenes")); } else { return(RedirectToAction("Login")); } }
public ActionResult CreateImagen(TB_IMAGENES obj) { if (Session["User"] != null) { ViewBag.Nombre = Session["FirstName"]; ViewBag.Apellido = Session["LastName"]; HttpPostedFileBase archivoBase = Request.Files[0]; if (archivoBase.ContentLength == 0) { ModelState.AddModelError("foto", "Es necesario seleccionar una Imagen.... "); return(View(obj)); } else { if (archivoBase.FileName.EndsWith(".jpg")) { WebImage image = new WebImage(archivoBase.InputStream); obj.url_imagen = image.ToString(); } else { ModelState.AddModelError("foto", "Solo se permite imagenes con formato JPG.... "); return(View(obj)); } } db.TB_IMAGENES.Add(obj); db.SaveChanges(); //sincroniza return(RedirectToAction("ListarImagenes")); } else { return(RedirectToAction("Login")); } }