Ejemplo n.º 1
0
        public ActionResult Crear(FormatoView formatoView)
        {
            try
            {
                string nombreFormato      = Request.Files[0].FileName;
                string descripcionFormato = Request.Form["txtDescripcionFormato"];
                string nombreCorto        = nombreFormato.Trim().Substring(nombreFormato.Trim().LastIndexOf('\\') + 1);
                string version            = Request.Form["txtVersion"];
                string codigo             = Request.Form["txtCodigo"];
                string carpetaBase        = Request.Form["txtCarpetaBase"];

                #region Verificar is ya existe el nombre del formato
                FormatoRepository fr = new FormatoRepository();

                Formato f = fr.Obtener(nombreCorto);
                if (f.Id > 0)
                {
                    formatoView.Formato.Archivo.Nombre = nombreFormato;
                    formatoView.Mensaje = "El nombre del formato ya existe.";
                }
                else
                {
                    f = new Formato();
                    f.Archivo.Nombre    = nombreCorto;
                    f.Archivo.Contenido = new byte[Request.Files[0].ContentLength];
                    Request.Files[0].InputStream.Read(f.Archivo.Contenido, 0, f.Archivo.Contenido.Length);
                    f.Descripcion = descripcionFormato;
                    f.Codigo      = codigo;
                    f.Version     = version;
                    f.CarpetaBase = carpetaBase;
                    f             = fr.Actualizar(f);
                    if (f.Id == 0)
                    {
                        formatoView.Mensaje = "Hubo un error al crear el formato.";
                    }
                    else
                    {
                        formatoView.Mensaje = "Formato creado satisfactoriamente.";
                    }
                }
                return(View("Crear", formatoView));

                #endregion
            }
            catch (Exception ex)
            {
                return(View("Mensaje", new AmbienteView {
                    Mensaje = ex.Message
                }));
            }
        }
Ejemplo n.º 2
0
 public ActionResult Obtener(string id)
 {
     try
     {
         FormatoView fv = new FormatoView();
         fv.Mensaje = "";
         FormatoRepository fr = new FormatoRepository();
         Formato           f  = fr.Obtener(int.Parse(id));
         fv.Formato = f;
         return(View("Obtener", fv));
     }
     catch (Exception ex)
     {
         return(View("Mensaje", new AmbienteView {
             Mensaje = ex.Message
         }));
     }
 }