コード例 #1
0
        public ActionResult Reporte(int id)
        {
            TempData["componente"] = id;
            TempData.Keep();
            var componenteelectrico = _componentesElectricos_Manager.Find(id);

            ViewBag.ComponentesElectronicos_Tipos =
                new SelectList(_componentesElectricos_Manager.FindTipos(), "descripcion", "descripcion");

            ViewBag.ArchivosFotografia = _obrasManager.FindFotografiasComponentesElectronicos(id);

            ViewBag.Sustitucion2 =
                new SelectList(new[] { new { ID = "SI", Name = "SI" }, new { ID = "NO", Name = "NO" }, }, "ID", "Name", componenteelectrico.Sustitucion);

            TempData["obra"] = TempData["obra_id"];

            ViewBag.obra = _obrasManager.Find(Convert.ToInt32(TempData["obra_id"]));

            if (componenteelectrico == null)
            {
                // TempData["FlashError"] = MensajesResource.ERROR_MensajesInstitucionales_IdIncorrecto;
                return(RedirectToAction("Index"));
            }

            var componenteelectricoModel = new ComponenteElectricoViewModel()
            {
                Tipo             = componenteelectrico.Tipo,
                Caracteristicas  = componenteelectrico.Caracteristicas,
                Descripcion      = componenteelectrico.Descripcion,
                Marca            = componenteelectrico.Marca,
                Modelo           = componenteelectrico.Modelo,
                Serial           = componenteelectrico.Serial,
                FechaFabricado   = componenteelectrico.FechaFabricado.ToString(),
                Duracion         = componenteelectrico.Duracion.ToString(),
                Sustitucion      = componenteelectrico.Sustitucion,
                Fotografia       = componenteelectrico.Fotografia,
                FechaSustitucion = componenteelectrico.FechaSustitucion.ToString(),
                FechaAlerta      = componenteelectrico.FechaAlerta.ToString()
            };

            return(PartialView(componenteelectricoModel));
        }
コード例 #2
0
        public ActionResult Crear(ComponenteElectricoViewModel model, FormCollection collection)
        {
            var Url    = "";
            var pdfUrl = "";

            ViewBag.obra = _obrasManager.Find(Convert.ToInt32(TempData["obra"]));



            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {/*
              * HttpPostedFileBase pdf = Request.Files["Pdf"];
              *
              * if (pdf != null && pdf.ContentLength > 0)
              * {
              *     pdfUrl = CargarPdf(pdf);
              * }
              * else { pdfUrl = ""; }
              */
                obras   obra   = _obrasManager.Find(Convert.ToInt32(TempData["obra"]));
                equipos equipo = _equiposManager.Find(Convert.ToInt32(TempData["equipo"]));

                componenteselectricos ce = _componentesElectricos_Manager.Crear(Convert.ToInt32(TempData["equipo"]),
                                                                                model.Tipo,
                                                                                model.Caracteristicas,
                                                                                model.Descripcion,
                                                                                model.Marca,
                                                                                model.Modelo,
                                                                                model.Serial,
                                                                                model.FechaFabricado,
                                                                                model.Duracion,
                                                                                model.Sustitucion,
                                                                                pdfUrl.Trim(), model.FechaSustitucion, model.FechaAlerta, obra.Nombre, equipo.Nombre);

                HttpPostedFileBase file;

                for (int i = 0; i < Request.Files.Count; i++)
                {
                    file = Request.Files[i];
                    var d = Request.Files.AllKeys[i].ToString();

                    if (d == "Pdf" && file.FileName != "")
                    {
                        Url = CargarPdf(file);
                        _obrasManager.AgregarArchivos(ce.Id, Url, "componenteselectricos", "fotografia");
                    }
                }
                //TempData["FlashSuccess"] = MensajesResource.INFO_MensajesInstitucionales_CreadoCorrectamente;
                return(RedirectToAction("ComponentesElectronicos", "AdministrarComponentesElectronicos", new { @id = TempData["equipo"] }));
            }
            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));
            }
        }
コード例 #3
0
        public ActionResult Editar(int id, ComponenteElectricoViewModel model)
        {
            var Url    = "";
            var pdfUrl = "";

            var componenteelectrico = _componentesElectricos_Manager.Find(id);

            ViewBag.obra = _obrasManager.Find(Convert.ToInt32(TempData["obra_id"]));

            ViewBag.Sustitucion2 =
                new SelectList(new[] { new { ID = "SI", Name = "SI" }, new { ID = "NO", Name = "NO" }, }, "ID", "Name", componenteelectrico.Sustitucion);

            if (componenteelectrico == 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 = componenteelectrico.Fotografia; }
              */
                _componentesElectricos_Manager.Actualizar(
                    id,
                    model.Tipo,
                    model.Caracteristicas,
                    model.Descripcion,
                    model.Marca,
                    model.Modelo,
                    model.Serial,
                    model.FechaFabricado,
                    model.Duracion,
                    model.Sustitucion,
                    pdfUrl.Trim(), model.FechaSustitucion, model.FechaAlerta);

                HttpPostedFileBase file;

                for (int i = 0; i < Request.Files.Count; i++)
                {
                    file = Request.Files[i];
                    var d = Request.Files.AllKeys[i].ToString();

                    if (d == "Pdf" && file.FileName != "")
                    {
                        Url = CargarPdf(file);
                        _obrasManager.AgregarArchivos(id, Url, "componenteselectricos", "fotografia");
                    }
                }
                // TempData["FlashSuccess"] = MensajesResource.INFO_UsuarioNazan_ActualizadoCorrectamente;
                // return RedirectToAction("Editar", "AdministrarComponentesElectronicos", new { @id = id });
                if (TempData["equipo_id"] != null)
                {
                    return(RedirectToAction("ComponentesElectronicos", "AdministrarComponentesElectronicos", new { @id = TempData["equipo_id"] }));
                }
                else
                {
                    return(RedirectToAction("Sustituciones", "AdministrarComponentesElectronicos"));
                }

                // return RedirectToAction("ComponentesElectronicos", "AdministrarComponentesElectronicos", new { @id = TempData["equipo_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));
            }
        }