public ActionResult EditarPreguntaInvestigacion([Bind(Include = "id,idGrupoInvestigacion,Consecutivo,Pregunta,FechaCreacion,FechaModificacion,PreguntaPrincipal")] tblPreguntaInvestigacion tbresearchquestion)
        {
            string userId = AspNetUsers.GetUserId(User.Identity.Name);
            int    idRol  = tblMiembroGrupo.GetRoleMiembro(userId, tbresearchquestion.idGrupoInvestigacion);

            if (idRol != 1)
            {
                return(RedirectToAction("Index", new { code = 999, id = tbresearchquestion.idGrupoInvestigacion }));
            }
            if (ModelState.IsValid)
            {
                tbresearchquestion.FechaModificacion = DateTime.Now;
                db.Entry(tbresearchquestion).State   = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", new { code = 120 }));
            }
            return(View(tbresearchquestion));
        }
        public ActionResult RegistrarGrupo([Bind(Include = "id,Codigo,Nombre,FechaCreacion,TipoGrupo,Avatar,idInstitucion,idLineaInvestigacion,idUsuario")] tblGrupoInvestigacion tblgrupoinvestigacion)
        {
            /// Datos del grupo de investigación adicionales
            /// que se cargan en tiempo de ejecución no en el modelo
            ///
            string userId = AspNetUsers.GetUserId(User.Identity.Name);

            tblgrupoinvestigacion.FechaCreacion = DateTime.Now;
            tblgrupoinvestigacion.Codigo        = dl.Codigos.ResearchGroupCode();
            if (ModelState.IsValid)
            {
                try
                {
                    string fileName = "imagen-no-disponible.jpg";
                    foreach (string file in Request.Files)
                    {
                        HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
                        if (hpf.ContentLength == 0)
                        {
                            continue;
                        }
                        string folderPath = Server.MapPath("~/Images/Avatars/");
                        Directory.CreateDirectory(folderPath);
                        string ext = Path.GetExtension(hpf.FileName);
                        fileName = string.Format("img-{0}{1}", tblgrupoinvestigacion.Codigo, ext);
                        string savedFileName = Server.MapPath("~/Images/Avatars/" + fileName);
                        hpf.SaveAs(savedFileName);
                        tblgrupoinvestigacion.Avatar = fileName;
                    }
                    db.tblGrupoInvestigacion.Add(tblgrupoinvestigacion);
                    db.SaveChanges();

                    /// Creación de la reflexion
                    ///
                    tblReflexionProyectoInvestigacion tblreflexion = new tblReflexionProyectoInvestigacion();
                    tblreflexion.idGrupoInvestigacion = tblgrupoinvestigacion.id;
                    tblreflexion.FechaInicio          = DateTime.Now;
                    tblreflexion.Proceso        = "Proceso";
                    tblreflexion.Motivacion     = "Motivación";
                    tblreflexion.Reflexion      = "Reflexión";
                    tblreflexion.ConceptoAsesor = "Espacio para el Asesor";
                    db.tblReflexionProyectoInvestigacion.Add(tblreflexion);
                    db.SaveChanges();


                    /// Creación de la pregunta
                    ///
                    tblPreguntaInvestigacion tblpregunta;

                    if (tblgrupoinvestigacion.TipoGrupo == 2)
                    {
                        for (int i = 0; i <= 5; i++)
                        {
                            tblpregunta = new tblPreguntaInvestigacion();
                            tblpregunta.idGrupoInvestigacion = tblgrupoinvestigacion.id;
                            tblpregunta.Consecutivo          = i;
                            tblpregunta.FechaCreacion        = DateTime.Now;
                            if (i == 0)
                            {
                                tblpregunta.Pregunta          = "Escriba la Pregunta seleccionada";
                                tblpregunta.PreguntaPrincipal = true;
                            }
                            else
                            {
                                tblpregunta.Pregunta          = string.Format("Escriba la Pregunta {0}", i.ToString());
                                tblpregunta.PreguntaPrincipal = false;
                            }
                            db.tblPreguntaInvestigacion.Add(tblpregunta);
                            db.SaveChanges();
                        }

                        tblPreguntaProyectoInvestigacion tblpreguntaproyecto = new tblPreguntaProyectoInvestigacion();
                        tblpreguntaproyecto.idGrupoInvestigacion = tblgrupoinvestigacion.id;
                        db.tblPreguntaProyectoInvestigacion.Add(tblpreguntaproyecto);
                        db.SaveChanges();

                        tblProblemaInvestigacion tblproblemainvestigacion = new tblProblemaInvestigacion();

                        tblproblemainvestigacion.idGrupoInvestigacion = tblgrupoinvestigacion.id;
                        db.tblProblemaInvestigacion.Add(tblproblemainvestigacion);
                        db.SaveChanges();

                        tblProblemaProyectoInvestigacion tblproblemaproyectoinvestigacion = new tblProblemaProyectoInvestigacion();

                        tblproblemaproyectoinvestigacion.idGrupoInvestigacion = tblgrupoinvestigacion.id;
                        db.tblProblemaProyectoInvestigacion.Add(tblproblemaproyectoinvestigacion);
                        db.SaveChanges();
                    }
                    else
                    {
                        tblDocumentosSoporte tbldocumentos = new tblDocumentosSoporte();
                        tbldocumentos.idGrupoInvestigacion = tblgrupoinvestigacion.id;
                        db.tblDocumentosSoporte.Add(tbldocumentos);
                        db.SaveChanges();
                    }
                    /// Grupo creado satisfactoriamente
                    return(RedirectToAction("Index", new { code = 10 }));
                }
                catch (Exception)
                {
                    return(RedirectToAction("Index", new { code = 20 }));
                }
            }
            ViewBag.idLineaInvestigacion    = new SelectList(db.tblLineaInvestigacion, "id", "Nombre");
            tblgrupoinvestigacion.idUsuario = AspNetUsers.GetUserId(User.Identity.Name);
            return(View(tblgrupoinvestigacion));
        }
        /// <summary>
        /// Modificar pregunta
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult EditarPreguntaInvestigacion(int id = 0)
        {
            tblPreguntaInvestigacion model = db.tblPreguntaInvestigacion.Find(id);

            return(PartialView("_EditarPreguntaInvestigacion", model));
        }