Exemplo n.º 1
0
        public JsonResult Create(MCapacitacion Mcapacitacion)
        {
            Respuesta respuesta = new Respuesta();

            if (sesion.esAdministrador(db))
            {
                string ruta = Server.MapPath(dir_capacitaciones);
                if (ModelState.IsValid)
                {
                    capacitaciones c = new capacitaciones();
                    c.comentarios = Mcapacitacion.comentarios;
                    c.fecha       = Mcapacitacion.fecha;
                    c.encargado   = Mcapacitacion.encargado;
                    c.nom_File    = Mcapacitacion.File;
                    c.periodo     = Mcapacitacion.periodo;
                    c.tema        = Mcapacitacion.tema;
                    // se guardan los ficheros
                    String[] resultado = Archivo.subir(Request.Files, ruta);
                    // si se guarda el fichero en el servidor, se guarda el registro en la BD
                    if (resultado[0].Equals("ok"))
                    {
                        // se asigna el nombre
                        c.nom_File = resultado[1];
                        // se guarda en la BD
                        String guardar = Mcapacitacion.guardar(c, db);
                        // se comprueba si se gusrdó
                        if (guardar != null)
                        {
                            respuesta.RESPUESTA = "OK";
                            respuesta.MENSAJE   = "Capacitación registrada.";
                        }
                        else
                        {
                            respuesta.RESPUESTA = "ERROR";
                            respuesta.MENSAJE   = "Error al registrar la capacitación.";
                            Archivo.elimiarFichero(ruta, resultado[1]);
                        }
                    }
                    else
                    {
                        respuesta.RESPUESTA = "ERROR";
                        respuesta.MENSAJE   = resultado[1];
                    }
                }
                else
                {
                    respuesta.RESPUESTA = "ERROR";
                    respuesta.MENSAJE   = "Los datos ingresados son incorrecotos.";
                    //respuesta.DATOS = (from x in ModelState where ModelState[x.Key].Errors.Count > 0 select (x.Value)).ToArray();
                }
            }
            else
            {
                respuesta.RESPUESTA = "LOGIN";
            }
            return(Json(respuesta));
        }
Exemplo n.º 2
0
        //
        // GET: /Capacitacion/Details/5

        public ActionResult Details(int id = 0)
        {
            if (sesion.esAdministrador(db))
            {
                MCapacitacion mCapacitacion = new MCapacitacion().getCapacitacionId(db, id);
                if (mCapacitacion == null)
                {
                    return(HttpNotFound());
                }
                return(View(mCapacitacion));
            }
            else
            {
                return(Redirect("~/Inicio/Login"));
            }
        }