public ActionResult Edit(DocumentoModelo documentoModelo, HttpPostedFileBase file) { //Veja se um arquivo foi selecionado, senão gere erro. Depois veja se tem nomes identicos e então substitua o arquivo antigo pelo novo. Senão gere erro. if (file != null && file.ContentLength > 0) { var nomeArquivo = new Regex(@"[^\\]*$").Match(file.FileName).Value; if (documentoModelo.NomeArquivo == nomeArquivo) { string arquivoFileName = Path.GetFileName(file.FileName); string FolderPath = Path.Combine(Server.MapPath("~/Templates"), arquivoFileName); file.SaveAs(FolderPath); documentoModelo.EnderecoArquivo = FolderPath; } else { ModelState.AddModelError("NomeArquivo", "O nome do arquivo atualizado deve ser igual ao original!"); } } else { ModelState.AddModelError("NomeArquivo", "Selecione o arquivo atualizado!"); } //senão incorreu em nehum erro (gerado no ModelState então) if (ModelState.IsValid) { db.Entry(documentoModelo).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(documentoModelo)); }
public int Guardar(DocumentoModelo entidad) { Tabla.Codigo = entidad.Codigo; Tabla.Descripcion = entidad.Descripcion; Tabla.TipoAuditoria = entidad.TipoAuditoria; Tabla.TipoEntidad = entidad.TipoEntidad; Tabla.OrigenDatos = entidad.OrigenDatos; Tabla.Activo = entidad.Activo; Tabla.Guardar(); return(Tabla.Codigo); }
public void Editar(DocumentoModelo objEditar) { try { string Json = JsonConvert.SerializeObject(objEditar); ObjDocumento.Editar("4", Json); } catch (Exception ex) { Mensajes.EscribirLog(Constantes.MensajeError, ex.Message, "SAF.Negocios.DocumentoNegocio - Editar"); throw; } }
public ActionResult DeleteConfirmed(int id) { DocumentoModelo documentoModelo = db.DocumentoModeloes.Find(id); if (System.IO.File.Exists(documentoModelo.EnderecoArquivo)) { System.IO.File.Delete(documentoModelo.EnderecoArquivo); } db.DocumentoModeloes.Remove(documentoModelo); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: DocumentoModelo/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DocumentoModelo documentoModelo = db.DocumentoModeloes.Find(id); if (documentoModelo == null) { return(HttpNotFound()); } return(View(documentoModelo)); }
public bool Borrar(int id) { try { DocumentoModelo objBorrar = new DocumentoModelo(); objBorrar.Id = (short)id; string Json = JsonConvert.SerializeObject(objBorrar); return(ObjDocumento.Borrar("5", Json)); } catch (Exception ex) { Mensajes.EscribirLog(Constantes.MensajeError, ex.Message, "SAF.Negocios.DocumentoNegocio - Borrar"); throw; } }
public ActionResult DocumentoInsertar(DocumentoModelo objInsertar) { try { if (ModelState.IsValid) { SesionNegocio objSesionNegocio = new SesionNegocio(); objDocumento.AsignarSesion(objSesionNegocio.GetObjectFromJson <SesionModelo>(HttpContext.Session, "SesionUsuario")); objDocumento.Insertar(objInsertar); } return(Json("{ success: 'true'}")); } catch (Exception ex) { Mensajes.EscribirLog(Constantes.MensajeError, ex.Message, "DocumentoController - Insertar"); return(View()); } }
public ActionResult Create(DocumentoModelo documentoModelo, HttpPostedFileBase UploadArquivo) { //Faça upoload do arquivo. Se ele não existir gere um erro. if (UploadArquivo != null && UploadArquivo.ContentLength > 0) { string arquivoFileName = Path.GetFileName(UploadArquivo.FileName); string FolderPath = Path.Combine(Server.MapPath("~/Templates"), arquivoFileName); UploadArquivo.SaveAs(FolderPath); documentoModelo.EnderecoArquivo = FolderPath; if (ModelState.IsValid) { db.DocumentoModeloes.Add(documentoModelo); db.SaveChanges(); return(RedirectToAction("Index")); } } else { ViewBag.Message = "Selecione um arquivo"; } return(View(documentoModelo)); }