コード例 #1
0
        public ActionResult Actualizar(AmbienteView ambienteView)
        {
            try
            {
                string id                    = Request.Form["txtId"];
                string nombreAmbiente        = Request.Form["txtNombreAmbiente"];
                string abreviatura           = Request.Form["txtAbreviatura"];
                int    orden                 = int.Parse(Request.Form["txtOrden"]);
                bool   final                 = Request.Form["chkFinal"] == "on";
                bool   fechaObligatoria      = Request.Form["chkFechaObligatoria"] == "on";
                bool   apruebaCalidad        = Request.Form["chkApruebaCalidad"] == "on";
                bool   envioPrimeraSolicitud = Request.Form["chkEnvioPrimeraSolicitud"] == "on";
                int    observacionId         = 0;
                if (Request.Form["cboObservaCalidad"] != null)
                {
                    observacionId = int.Parse(Request.Form["cboObservaCalidad"]);
                }

                Ambiente a = new Ambiente();
                a.Id                    = int.Parse(id);
                a.Nombre                = nombreAmbiente;
                a.Abreviatura           = abreviatura;
                a.Orden                 = orden;
                a.Final                 = final;
                a.FechaObligatoria      = fechaObligatoria;
                a.ApruebaCalidad        = apruebaCalidad;
                a.EnvioPrimeraSolicitud = envioPrimeraSolicitud;
                a.ObservaCalidad        = new Observacion {
                    Id = observacionId
                };

                AmbienteRepository ar = new AmbienteRepository();

                a = ar.Actualizar(a);
                if (a.Id == 0)
                {
                    ambienteView.Mensaje = "Hubo un error al actualizar el ambiente";
                    return(View("Crear", ambienteView));
                }

                ar.EliminarCorreos(a.Id);

                foreach (string key in Request.Form.AllKeys)
                {
                    if (key.IndexOf("txtCorreo") >= 0)
                    {
                        // Actualizar Correo
                        int    correoId = int.Parse(key.Substring("txtCorreo".Length));
                        Correo correo   = new Correo();
                        correo.Direccion = Request.Form["txtCorreo" + correoId.ToString()];
                        correo.Id        = correoId;
                        ar.InsertarAmbienteCorreo(correo, a.Id);
                    }
                    if (key.IndexOf("txtNuevoCorreo") >= 0)
                    {
                        // Insertar Correo
                        int    correoId = int.Parse(key.Substring("txtNuevoCorreo".Length));
                        Correo correo   = new Correo();
                        correo.Direccion = Request.Form["txtNuevoCorreo" + correoId.ToString()];
                        correo.Id        = 0;
                        ar.InsertarAmbienteCorreo(correo, a.Id);
                    }
                }

                a.Correos = ar.ListarCorreos(a.Id);

                ObservacionRepository or            = new ObservacionRepository();
                List <Observacion>    observaciones = or.Listar(String.Empty);
                AmbienteView          pp            = new AmbienteView();
                pp.Mensaje       = "Ambiente Actualizado";
                pp.Ambiente      = a;
                pp.Observaciones = observaciones;
                return(View("Obtener", pp));
            }
            catch (Exception ex)
            {
                return(View("Mensaje", new AmbienteView {
                    Mensaje = ex.Message
                }));
            }
        }