public ActionResult Create([Bind(Include = "idEditable,fecha,entidad,instrumento,documento,tipo_documento,img,descripcion")] tblEditables tblEditables) { if (ModelState.IsValid) { if (Request.Files.Count > 0) { HttpPostedFileBase file = Request.Files[0]; if (file.ContentLength > 0) { var img = (file.FileName).ToLower(); tblEditables.img = "/Content/Editables/" + img; file.SaveAs(Server.MapPath("~/Content/Editables/") + img); } db.tblEditables.Add(tblEditables); db.SaveChanges(); /*NOTIFICACION*/ ApplicationDbContext dbs = new ApplicationDbContext(); Notifications notificacion = new Notifications(); notificacion.Module = "Editables"; notificacion.Message = string.Format("Registro un nuevo archivo editable"); notificacion.Date = DateTime.Now; notificacion.Viewed = false; notificacion.Usuario_Id = User.Identity.GetUserId(); dbs.Notification.Add(notificacion); dbs.SaveChanges(); /*FIN NOTIFICACION*/ return(RedirectToAction("Index")); } } return(View(tblEditables)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblEditables tblEditables = db.tblEditables.Find(id); if (tblEditables == null) { return(HttpNotFound()); } return(View(tblEditables)); }
public ActionResult Edit([Bind(Include = "idEditable,fecha,entidad,instrumento,documento,tipo_documento,img,descripcion")] tblEditables tblEditables) { if (ModelState.IsValid) { if (Request.Files.Count > 0) { HttpPostedFileBase file = Request.Files[0]; if (file.ContentLength > 0) { var img = (file.FileName).ToLower(); tblEditables.img = "/Content/Editables/" + img; file.SaveAs(Server.MapPath("~/Content/Editables/") + img); } var queryarchivo = (from x in db.tblEditables where x.idEditable == tblEditables.idEditable select x.img).First(); if (file.ContentLength == 0) { //var query = (from x in db.tblLibros // where x.idlibros == tblLibros.idlibros // select x.word).First(); //tblLibros.img = query.img; tblEditables.img = queryarchivo; } } db.Entry(tblEditables).State = EntityState.Modified; db.SaveChanges(); /*NOTIFICACION*/ ApplicationDbContext dbs = new ApplicationDbContext(); Notifications notificacion = new Notifications(); notificacion.Module = "Editables"; notificacion.Message = string.Format("Edito un archivo editable"); notificacion.Date = DateTime.Now; notificacion.Viewed = false; notificacion.Usuario_Id = User.Identity.GetUserId(); dbs.Notification.Add(notificacion); dbs.SaveChanges(); /*FIN NOTIFICACION*/ return(RedirectToAction("Index")); } return(View(tblEditables)); }
public ActionResult DeleteConfirmed(int id) { tblEditables tblEditables = db.tblEditables.Find(id); db.tblEditables.Remove(tblEditables); db.SaveChanges(); /*NOTIFICACION*/ ApplicationDbContext dbs = new ApplicationDbContext(); Notifications notificacion = new Notifications(); notificacion.Module = "Editables"; notificacion.Message = string.Format("Elimino un archivo editable"); notificacion.Date = DateTime.Now; notificacion.Viewed = false; notificacion.Usuario_Id = User.Identity.GetUserId(); dbs.Notification.Add(notificacion); dbs.SaveChanges(); /*FIN NOTIFICACION*/ return(RedirectToAction("Index")); }