public ActionResult ConsultarId(int id) { modeloArchivo bd = new modeloArchivo(); var lista = bd.ObtenerArchivoPorId(id); return(View(lista)); }
public ActionResult Lista() { modeloArchivo bd = new modeloArchivo(); var lista = bd.ObtenerArchivos(); return(View(lista)); }
public ActionResult Actualizar(int idNoticia) { modeloNoticia bd = new modeloNoticia(); ViewData["IdUsuario"] = 1; //Administrador modeloArchivo bdAr = new modeloArchivo(); ViewData["Archivo"] = (from item in (bdAr.ObtenerArchivos()) where item.IdNoticia == idNoticia select new clsArchivo { IdArchivo = item.IdArchivo, IdNoticia = item.IdNoticia, Ruta = item.Ruta, Tipo = item.Tipo }).SingleOrDefault(); var res = bd.ObtenerNoticiaPorId(idNoticia); var lista = new clsNoticia { IdNoticia = res.IdNoticia, TextoNoticia = res.Texto, TipoNoticia = res.TipoNoticia, TituloNoticia = res.Titulo, FechaNoticia = res.Fecha, IdUsuario = 1 }; return(View(lista)); }
public JsonResult Actualizar([Bind] clsArchivo archivo) { if (archivo.Tipo) { modeloArchivo bd = new modeloArchivo(); if (bd.ActualizarArchivo(archivo) > 0) { return(Json(new { ok = true, mensaje = archivo }, JsonRequestBehavior.AllowGet)); } return(Json(new { ok = false, mensaje = "No se agregó el archivo" }, JsonRequestBehavior.AllowGet)); } else { if (Request.Files.Count > 0) { try { HttpFileCollectionBase files = Request.Files; HttpPostedFileBase file = files[0]; string fname; fname = file.FileName; fname = Path.Combine(Server.MapPath("~/Archivos/"), fname); var flocalName = "../Archivos/" + file.FileName; file.SaveAs(fname); archivo.Ruta = flocalName; modeloArchivo bd = new modeloArchivo(); if (bd.ActualizarArchivo(archivo) > 0) { return(Json(new { ok = true, mensaje = archivo }, JsonRequestBehavior.AllowGet)); } return(Json(new { ok = false, mensaje = "No se agregó el archivo" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { ok = false, mensaje = "No se agregó el archivo" }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { ok = false, mensaje = "No se agregó el archivo. Intenta con otro, este probablemente ya existe en la base de datos" }, JsonRequestBehavior.AllowGet)); } } }
public JsonResult Eliminar(int id) { try { modeloArchivo bd = new modeloArchivo(); var noticia = bd.ObtenerArchivoPorId(id); if (bd.BorrarArchivo(noticia) > 0) { return(Json(new { ok = true, mensaje = noticia }, JsonRequestBehavior.AllowGet)); } return(Json(new { ok = false, mensaje = "No se agregó el archivo" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { ok = false, mensaje = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult ConsultarId(int id) { modeloNoticia bd = new modeloNoticia(); var res = bd.ObtenerNoticiaPorId(id); var lista = new clsNoticia { IdNoticia = res.IdNoticia, TextoNoticia = res.Texto, TipoNoticia = res.TipoNoticia, TituloNoticia = res.Titulo, FechaNoticia = res.Fecha, IdUsuario = 1 }; modeloArchivo bdAr = new modeloArchivo(); var archivo = (from item in (bdAr.ObtenerArchivos()) where item.IdNoticia == id select new clsArchivo { IdArchivo = item.IdArchivo, IdNoticia = item.IdNoticia, Ruta = item.Ruta, Tipo = item.Tipo }).SingleOrDefault(); ViewData["Archivo"] = archivo; if (archivo != null) { var extension = string.Empty; extension = Path.GetExtension(archivo.Ruta); ViewData["extension"] = (archivo.Tipo ? "video" : "imagen"); } else { ViewData["extension"] = " "; } ViewBag.Etiqueta = lista.TipoNoticia; return(View("Detalle", lista)); }
public ActionResult Index() { string tipoNoticia = ""; var listaNoticias = new List <clsNoticiaArchivo>(); modeloNoticia mn = new modeloNoticia(); modeloArchivo ma = new modeloArchivo(); if (tipoNoticia.Equals("")) { listaNoticias = (from noticias in (mn.ObtenerNoticias()) from archivos in (ma.ObtenerArchivos()) where noticias.TipoNoticia != "" && noticias.IdNoticia == archivos.IdNoticia orderby noticias.Fecha select new clsNoticiaArchivo { Archivo = archivos, Noticia = noticias }).ToList(); ViewBag.Etiqueta = "Home"; } else { listaNoticias = (from noticias in (mn.ObtenerNoticias()) from archivos in (ma.ObtenerArchivos()) where noticias.TipoNoticia == tipoNoticia && noticias.IdNoticia == archivos.IdNoticia orderby noticias.Fecha select new clsNoticiaArchivo { Archivo = archivos, Noticia = noticias }).ToList(); ViewBag.Etiqueta = tipoNoticia; } return(View(listaNoticias)); }