public IActionResult BuscarPerguntaPorId(int id)
        {
            try
            {
                // pergunta p = _context.perguntas
                //     .Where(c => c.idPergunta == id)
                //     .Include(d => d.alternativas)
                //     .FirstOrDefault();

                pergunta pergunta = _perguntaRepository
                                    .Listar(new string[] { "alternativas", "desafio" })
                                    .FirstOrDefault();

                pergunta.desafio.perguntas = null;

                if (pergunta == null)
                {
                    return(NotFound(id));;
                }
                else
                {
                    return(Ok(pergunta));
                }
            }
            catch (System.Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Esempio n. 2
0
 public ActionResult Edit([Bind(Include = "Id, id_evento,pergunta1")] pergunta pergunta)
 {
     if (ModelState.IsValid)
     {
         pnPerguntas.Editar(pergunta);
         return(RedirectToAction("Index"));
     }
     ViewBag.id_evento = new SelectList(pnEventos.PegarDB(), "Id", "Nome", pergunta.id_evento);
     return(View(pergunta));
 }
Esempio n. 3
0
 public static void Editar(pergunta ec)
 {
     try
     {
         EventosEntities db = new EventosEntities();
         db.Entry(ec).State = EntityState.Modified;
         db.SaveChanges();
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 4
0
 public static void Cadastrar(pergunta ec)
 {
     try
     {
         EventosEntities db = new EventosEntities();
         db.pergunta.Add(ec);
         db.SaveChanges();
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 5
0
        // GET: perguntas/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            pergunta pergunta = pnPerguntas.Procurar(id);

            if (pergunta == null)
            {
                return(HttpNotFound());
            }
            return(View(pergunta));
        }
Esempio n. 6
0
        // GET: perguntas/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            pergunta pergunta = pnPerguntas.Procurar(id);

            if (pergunta == null)
            {
                return(HttpNotFound());
            }
            ViewBag.id_evento = new SelectList(pnEventos.PegarDB(), "Id", "Nome", pergunta.id_evento);
            return(View(pergunta));
        }
Esempio n. 7
0
 public static pergunta Procurar(int?id)
 {
     try
     {
         EventosEntities db = new EventosEntities();
         pergunta        u  = db.pergunta.Find(id);
         if (u == null)
         {
             return(null);
         }
         return(u);
     }
     catch (Exception)
     {
         throw;
     }
 }
        public IActionResult Cadastrar([FromBody] pergunta postagem)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _perguntaRepository.Inserir(postagem);
                    return(Ok(postagem));
                }

                IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);

                return(BadRequest(allErrors));
            }
            catch (System.Exception e)
            {
                return(BadRequest(e.Message));
            }
        }