public IHttpActionResult Post(ConsultaNivelTemas dados)
        {
            //var rnd = new Random(DateTime.Now.Millisecond);
            var perguntas = new List <ViewPergunta>();
            var retorno   = new ListViewPerguntaResposta();

            ValidaDadosConsulta(dados);

            using (ctx = new JogoMasterEntities())
            {
                dados.idsTema.ForEach(tema =>
                {
                    var perguntasBanco = ctx.Perguntas
                                         .Where(x => x.IdNivel == dados.idNivel && x.IdTema == tema)
                                         .Select(x => new ViewPergunta()
                    {
                        Id          = x.Id,
                        Pergunta    = x.Pergunta1,
                        IdNivel     = x.IdNivel,
                        IdTema      = x.IdTema,
                        Patrocinada = x.Patrocinada
                    }).ToList();

                    perguntas = perguntasBanco.OrderBy(x => Guid.NewGuid()).Take(4).ToList();

                    perguntas.ForEach(pergunta =>
                    {
                        var res = ctx.Respostas
                                  .Where(x => x.IdPergunta == pergunta.Id)
                                  .Select(x => new ViewResposta()
                        {
                            Id         = x.Id,
                            Correta    = x.Correta,
                            Resposta   = x.Resposta1,
                            IdPergunta = x.IdPergunta
                        })
                                  .ToList();

                        var perRes = new ViewPerguntaResposta
                        {
                            pergunta  = pergunta,
                            respostas = res
                        };

                        retorno.lista.Add(perRes);
                    });
                });
            }
            return(Ok(retorno.lista));
        }
        public IHttpActionResult Get()
        {
            List <ViewPergunta>         perguntas = null;
            List <ViewResposta>         respostas = null;
            List <ViewPerguntaResposta> retorno   = null;

            using (ctx = new JogoMasterEntities())
            {
                perguntas = ctx.Perguntas.Select(s => new ViewPergunta()
                {
                    Id          = s.Id,
                    Pergunta    = s.Pergunta1,
                    IdNivel     = s.IdNivel,
                    IdTema      = s.IdTema,
                    Patrocinada = s.Patrocinada
                }).ToList();

                respostas = ctx.Respostas.Select(s => new ViewResposta()
                {
                    Id         = s.Id,
                    Correta    = s.Correta,
                    Resposta   = s.Resposta1,
                    IdPergunta = s.IdPergunta
                }).ToList();
            }

            if (perguntas.Count == 0)
            {
                return(NotFound());
            }

            retorno = new List <ViewPerguntaResposta>();
            perguntas.ForEach(p =>
            {
                var item = new ViewPerguntaResposta
                {
                    pergunta  = p,
                    respostas = respostas.Where(x => x.IdPergunta == p.Id).ToList()
                };
                retorno.Add(item);
            });

            return(Ok(retorno));
        }
        public IHttpActionResult Get(int id)
        {
            ViewPergunta         pergunta  = null;
            List <ViewResposta>  respostas = null;
            ViewPerguntaResposta retorno   = null;

            using (ctx = new JogoMasterEntities())
            {
                pergunta = ctx.Perguntas
                           .Where(x => x.Id == id).Select(s => new ViewPergunta()
                {
                    Id          = s.Id,
                    Pergunta    = s.Pergunta1,
                    IdNivel     = s.IdNivel,
                    IdTema      = s.IdTema,
                    Patrocinada = s.Patrocinada
                }).FirstOrDefault();

                if (pergunta == null)
                {
                    return(NotFound());
                }

                respostas = ctx.Respostas
                            .Where(s => s.IdPergunta == pergunta.Id)
                            .Select(s => new ViewResposta()
                {
                    Id         = s.Id,
                    Correta    = s.Correta,
                    Resposta   = s.Resposta1,
                    IdPergunta = s.IdPergunta
                })
                            .ToList();

                retorno = new ViewPerguntaResposta
                {
                    pergunta  = pergunta,
                    respostas = respostas
                };
            }

            return(Ok(retorno));
        }