コード例 #1
0
        public ActionResult AgregarForo([Bind(Include = "id,idUser,idGrupoInvestigacion,Titulo,Mensaje,Fecha,Respuestas,idForo,FechaUltimaRespuesta")] tblForoProyectoInvestigacion tblforo)
        {
            tblforo.Fecha = DateTime.Now;

            int id = tblforo.idGrupoInvestigacion;
            InformacionGrupo infogrupo = new InformacionGrupo();
            var grupo = tblGrupoInvestigacion.Find(id);

            infogrupo.idGrupo     = id;
            infogrupo.Descripcion = grupo.tblPreguntaInvestigacion
                                    .Where(m => m.idGrupoInvestigacion == id)
                                    .Where(m => m.PreguntaPrincipal).Select(m => m.Pregunta).First();
            infogrupo.Institucion = grupo.tblInstitucion.Nombre;
            infogrupo.Municipio   = grupo.tblInstitucion.tblMunicipios.NombreMunicipio;
            infogrupo.NombreGrupo = grupo.Nombre;
            ViewBag.InfoGrupo     = infogrupo;

            if (ModelState.IsValid)
            {
                db.tblForoProyectoInvestigacion.Add(tblforo);
                db.SaveChanges();
                if (tblforo.idForo.HasValue)
                {
                    tblForoProyectoInvestigacion tblForoPrincipal = db.tblForoProyectoInvestigacion.Find(tblforo.idForo.Value);
                    int respuestas = db.tblForoProyectoInvestigacion.Where(m => m.idForo == tblforo.idForo.Value).Count();
                    tblForoPrincipal.Respuestas      = respuestas;
                    db.Entry(tblForoPrincipal).State = EntityState.Modified;
                    db.SaveChanges();
                }
                return(RedirectToAction("ForoProyecto", new { id = tblforo.idGrupoInvestigacion }));
            }
            return(RedirectToAction("ForoPoryecto", new { id = tblforo.idGrupoInvestigacion }));
        }
 public ActionResult AgregarForo([Bind(Include = "id,idUser,idGrupoInvestigacion,Titulo,Mensaje,Fecha,Respuestas,idForo,FechaUltimaRespuesta")] tblForoProyectoInvestigacion tblforo)
 {
     tblforo.Fecha = DateTime.Now;
     if (ModelState.IsValid)
     {
         db.tblForoProyectoInvestigacion.Add(tblforo);
         db.SaveChanges();
         if (tblforo.idForo.HasValue)
         {
             tblForoProyectoInvestigacion tblForoPrincipal = db.tblForoProyectoInvestigacion.Find(tblforo.idForo.Value);
             int respuestas = db.tblForoProyectoInvestigacion.Where(m => m.idForo == tblforo.idForo.Value).Count();
             tblForoPrincipal.Respuestas      = respuestas;
             db.Entry(tblForoPrincipal).State = EntityState.Modified;
             db.SaveChanges();
         }
         return(RedirectToAction("ForoProyecto", new { id = tblforo.idGrupoInvestigacion }));
     }
     return(RedirectToAction("ForoPoryecto", new { id = tblforo.idGrupoInvestigacion }));
 }