public ActionResult Editar(int id, ProtocoloViewModel model) { var protocolo = _protocolosManager.Find(id); var pdfUrl = ""; ViewBag.Obras = new SelectList(_obrasManager.FindObras(protocolo.obra_id), "id", "nombre", protocolo.obra_id); if (protocolo == null) { //TempData["FlashError"] = MensajesResource.ERROR_MensajesInstitucionales_IdIncorrecto; return(RedirectToAction("Index")); } try { HttpPostedFileBase pdf = Request.Files["Pdf"]; if (pdf != null && pdf.ContentLength > 0) { pdfUrl = CargarPdf(pdf); } else { pdfUrl = protocolo.Url; } if (pdfUrl == null) { pdfUrl = "null.jpg"; } _protocolosManager.Actualizar(protocolo.obra_id, id, model.Nombre, pdfUrl.Trim()); TempData["FlashSuccess"] = MensajesResource.INFO_Protocolos_ActualizadoCorrectamente; //return RedirectToAction("Editar", "AdministrarProtocolos", new { @id = id }); return(RedirectToAction("Protocolos", "AdministrarProtocolos", new { @id = TempData["previo_id"] })); } catch (BusinessException businessEx) { ModelState.AddModelError(string.Empty, businessEx.Message); return(View(model)); } catch (Exception e) { var log = CommonManager.BuildMessageLog( TipoMensaje.Error, ControllerContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString(), ControllerContext.Controller.ValueProvider.GetValue("action").RawValue.ToString(), e.ToString(), Request); CommonManager.WriteAppLog(log, TipoMensaje.Error); return(View(model)); } }
public ActionResult Editar(int id) { var protocolo = _protocolosManager.Find(id); if (protocolo.Nombre == null) { protocolo.Nombre = "null"; } if (protocolo.Url == null) { protocolo.Url = "null"; } ViewBag.Obras = new SelectList(_obrasManager.FindObras(Convert.ToInt32(TempData["obra_id"])), "id", "nombre", Convert.ToInt32(TempData["obra_id"])); TempData.Keep(); if (protocolo == null) { // TempData["FlashError"] = MensajesResource.ERROR_MensajesInstitucionales_IdIncorrecto; return(RedirectToAction("Index")); } var protocoloModel = new ProtocoloViewModel() { Nombre = protocolo.Nombre, Url = protocolo.Url, obra_id = protocolo.obra_id }; return(View(protocoloModel)); }
public ActionResult Crear(ProtocoloViewModel model, FormCollection collection) { var pdfUrl = ""; //ViewBag.Obras = //new SelectList(_obrasManager.FindAll(), "id", "nombre"); ViewBag.Obras = new SelectList(_obrasManager.FindObras(model.obra_id), "id", "nombre", model.obra_id); if (!ModelState.IsValid) { return(View(model)); } try { HttpPostedFileBase pdf = Request.Files["Pdf"]; if (pdf != null && pdf.ContentLength > 0) { pdfUrl = CargarPdf(pdf); } else { pdfUrl = "null"; } _protocolosManager.Crear(Convert.ToInt32(TempData["previo_id"]), model.obra_id, model.Nombre, pdfUrl.Trim()); TempData["FlashSuccess"] = MensajesResource.INFO_Protocolos_CreadoCorrectamente; return(RedirectToAction("Protocolos", "AdministrarProtocolos", new { @id = TempData["previo_id"] })); } catch (BusinessException businessEx) { ModelState.AddModelError(string.Empty, businessEx.Message); return(View(model)); } catch (Exception e) { var log = CommonManager.BuildMessageLog( TipoMensaje.Error, ControllerContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString(), ControllerContext.Controller.ValueProvider.GetValue("action").RawValue.ToString(), e.ToString(), Request); CommonManager.WriteAppLog(log, TipoMensaje.Error); ModelState.AddModelError(string.Empty, e.Message); return(View(model)); } }