public Boolean InserirPergunta()
 {
     try
     {
         using (var _context = new Show_de_PerguntasEntities())
         {
             Pergunta p = new Pergunta();
             p.enunciado = this.enunciado;
             p.Tema_IdTema = this.idTema;
             p.dificuldade = this.dificuldade;
             p.alternativaCorreta = this.alternativaCorreta;
             p.alternativaIncorreta1 = this.alternativaIncorreta1;
             p.alternativaIncorreta2 = this.alternativaIncorreta2;
             p.alternativaIncorreta3 = this.alternativaIncorreta3;
             p.alternativaIncorreta4 = this.alternativaIncorreta4;
             _context.AddToPerguntas(p);
             _context.SaveChanges();
             return true;
         }
     }
     catch (Exception)
     {
         return false;
         // throw;
     }
 }
示例#2
1
    protected void botMigrateModel_Click(object sender, EventArgs e)
    {
        lblStatus.Text = "Start Migration";
        DBHelper.ConnectionString = txtSourceConnection.Text;

        ModeloCompetencias _modelo = ModeloCompetencias.getDBModelo("JC", int.Parse(DDLModelos.SelectedValue));
        // agora vai criar o modelo na base de dados de produção
        _modelo.loadFull("JC", null);

        DBHelper.ConnectionString = this.txtDestConnection.Text;

        // cria o modelo
        ModeloCompetencias NovoModelo = new ModeloCompetencias();
        NovoModelo = _modelo;
        NovoModelo.reset();
        NovoModelo.updateDBModelo("JC");

        for (int i = 0; i < _modelo.Familias.Count; i++)
        {
            FamiliaCompetencias novaFam = new FamiliaCompetencias(NovoModelo);
            novaFam = NovoModelo.Familias.Values[i];
            novaFam.Modelo = NovoModelo;
            novaFam.reset();
            novaFam.SortIndex = i;
            novaFam.cloneDBFamilia("JC");
            for (int j = 0; j < _modelo.Familias.Values[i].Competencias.Count; j++)
            {
                Competencia novaComp = new Competencia();
                novaComp = NovoModelo.Familias.Values[i].Competencias.Values[j];
                novaComp.reset();
                novaComp.SortIndex = j;
                novaComp.Familia = novaFam;
                novaComp.cloneDBCompetencia("JC");
                for (int k = 0; k < _modelo.Familias.Values[i].Competencias.Values[j].Praticas.Count; k++)
                {
                    Pratica novaPrat = new Pratica();
                    novaPrat = NovoModelo.Familias.Values[i].Competencias.Values[j].Praticas.Values[k];
                    novaPrat.Competencia = novaComp;
                    novaPrat.reset();
                    novaPrat.SortIndex = k;
                    novaPrat.cloneDBPratica("JC");

                    for (int l = 0; l < _modelo.Familias.Values[i].Competencias.Values[j].Praticas.Values[k].Perguntas.Count; l++)
                    {
                        Pergunta novaPerg = new Pergunta();
                        novaPerg = NovoModelo.Familias.Values[i].Competencias.Values[j].Praticas.Values[k].Perguntas.Values[l];
                        novaPerg.reset();
                        novaPerg.Pratica = novaPrat;
                        novaPerg.SortIndex = l;
                        novaPerg.cloneDBPergunta("JC");
                    }

                }
            }
        }

        lblStatus.Text = "Migration Ended";
        // depois volta a colocar a limpar a coisa
        DBHelper.ConnectionString = "";
    }
    void CarregarTemas()
    {
        foreach (var tema in MasterScr.Temas)
        {
            string nomeTema = tema[0];
            string arquivoTema = tema[1];
            string imagemTema = tema[2];

            string arquivo = (Resources.Load("Temas/" + arquivoTema) as TextAsset).text;

            string[] linhas = arquivo.Split('\r');

            foreach (var linha in linhas)
            {
                string[] colunas = linha.Split(';');
                string pergunta = colunas[0];
                string respA = colunas[1];
                string respB = colunas[2];
                string respC = colunas[3];
                string respD = colunas[4];
                int respCerta = int.Parse(colunas[5]);

                Pergunta p = new Pergunta();

                p.Texto = pergunta;
                p.Respostas = new string[] { respA, respB, respC, respD };
                p.RespostaCerta = respCerta;
                p.Imagem = (Resources.Load("Imagens/" + imagemTema) as Texture2D);
                p.Tema = nomeTema;

                MasterScr.PerguntasCarregadas.Add(p);
            }
        }
    }
示例#4
0
        public async Task <IActionResult> Create([Bind("MelhorRespostaId,Id,Texto,AutorId,DataCriacao,Aberto")] Pergunta pergunta)
        {
            if (ModelState.IsValid)
            {
                _context.Add(pergunta);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AutorId"] = new SelectList(_context.Autores, nameof(Autor.Id), nameof(Autor.Nome), pergunta.AutorId);
            //ViewData["MelhorRespostaId"] = new SelectList(_context.Respostas, "Id", "Id", pergunta.MelhorRespostaId);
            pergunta.MelhorResposta = null;
            return(View(pergunta));
        }
        public void EditarPerguntaDepoisDeUmSegundoPassado7Dias()
        {
            Usuario  usuario  = new Usuario("Mateus", "Rua Mario Bandeira", "Costs aren't losses ", "https/foto.png", "*****@*****.**", "q1223");
            Pergunta pergunta = new Pergunta(usuario, "Java", "me ajuda");

            PropertyInfo prop = pergunta.GetType().GetProperty("DataPergunta", BindingFlags.Public | BindingFlags.Instance);

            if (prop != null && prop.CanWrite)
            {
                prop.SetValue(pergunta, pergunta.DataPergunta.AddDays(-7).AddSeconds(-1), null);
            }

            pergunta.Editar("teste", "teste", usuario);
        }
        private void ValidaResposta(ViewResposta dados)
        {
            Refute(string.IsNullOrEmpty(dados.Resposta), "Informe a Resposta.");
            using (ctx = new JogoMasterEntities())
            {
                Pergunta pergunta = null;
                pergunta = ctx.Perguntas.FirstOrDefault(x => x.Id == dados.IdPergunta);
                Refute(pergunta == null, "Id da Pergunta inválido.");

                Resposta resposta = null;
                resposta = ctx.Respostas.FirstOrDefault(x => x.Resposta1.ToLower() == dados.Resposta.ToLower() && x.IdPergunta == dados.IdPergunta);
                Refute(resposta != null, "Resposta já cadastrada.");
            }
        }
        private static void InsertData(Contexto context)
        {
            Pergunta pergunta1 = new Pergunta()
            {
                Descricao = "Qual sua tecnologia preferida?"
            };
            Pergunta pergunta2 = new Pergunta()
            {
                Descricao = "Qual tipo de tecnologia é mais importante pra você?"
            };
            Pergunta pergunta3 = new Pergunta()
            {
                Descricao = "Como você prefere passar seu tempo"
            };

            Profissao prof = new Profissao()
            {
                Nome = "Dev"
            };

            Resposta resp1Perg1 = new Resposta()
            {
                Descricao = "PHP",
                Pergunta  = pergunta1,
                Profissao = prof
            };
            Resposta resp2Perg1 = new Resposta()
            {
                Descricao = "C#",
                Pergunta  = pergunta1,
                Profissao = prof
            };

            pergunta2.Resposta = new List <Resposta>()
            {
                new Resposta()
                {
                    Descricao = "Machine Learning", Profissao = prof
                },
                new Resposta()
                {
                    Descricao = "Realidade Aumentada", Profissao = prof
                }
            };

            context.Perguntas.AddRange(pergunta1, pergunta2, pergunta3);
            context.Respostas.AddRange(resp1Perg1, resp2Perg1);

            context.SaveChanges();
        }
 public void Incluir(Pergunta pergunta)
 {
     try
     {
         if (Validar(pergunta))
         {
             perguntaDAO.Incluir(pergunta);
         }
     }
     catch (ExcecaoSAG ex)
     {
         throw new ExcecaoSAG(ex.getMsg());
     }
 }
        public Pergunta GetPergunta(int id)
        {
            SqlConnection con = new SqlConnection(connectionString);

            try

            {
                con.Open();

                SqlCommand cmd = new SqlCommand("PR_GetPergunta", con);

                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@Id", id);

                SqlDataReader dr = cmd.ExecuteReader();

                Pergunta obj = new Pergunta();

                while (dr.Read())

                {
                    obj.Id = dr["Id"].ToString().Equals(string.Empty) ? 0 : Convert.ToInt32(dr["Id"].ToString());

                    obj.Descricao = dr["Descricao"].ToString();

                    obj.IdAutor = dr["IdAutor"].ToString().Equals(string.Empty) ? 0 : Convert.ToInt32(dr["IdAutor"].ToString());

                    obj.IdCategoria = dr["IdCategoria"].ToString().Equals(string.Empty) ? 0 : Convert.ToInt32(dr["IdCategoria"].ToString());

                    obj.Ativo = dr["Ativo"].ToString().Equals(string.Empty) ? false : Convert.ToBoolean(dr["Ativo"].ToString());

                    obj.DataCriacao = dr["DataCriacao"].ToString().Equals(string.Empty) ? DateTime.MinValue : Convert.ToDateTime(dr["DataCriacao"].ToString());
                }

                return(obj);
            }

            catch (Exception ex)

            {
                throw ex;
            }

            finally

            {
                con.Close();
            }
        }
示例#10
0
        public bool PostPergunta(Pergunta Pergunta)
        {
            try

            {
                return(new PerguntaDAL().PostPergunta(Pergunta));
            }

            catch (Exception ex)

            {
                throw ex;  // retorna mensagem de erro
            }
        }
示例#11
0
        /// <summary>
        ///  Insere uma pergunta no Banco de Daodos
        ///  Inserindo junto as Imagens em ordem necessitando do list de imagens
        /// </summary>
        /// <param name="P">parametro do tipo Pergunta | com id</param>
        public void Alterar(Pergunta P)
        {
            SqlCommand comm = new SqlCommand("", Banco.Abrir());

            comm.CommandType = System.Data.CommandType.StoredProcedure;
            comm.CommandText = "AlterarPergunta";
            comm.Parameters.Add("@ID", SqlDbType.Int).Value           = P.ID;
            comm.Parameters.Add("@Titulo", SqlDbType.VarChar).Value   = P.Titulo;
            comm.Parameters.Add("@Texto", SqlDbType.Text).Value       = P.Texto;
            comm.Parameters.Add("@Visibilidade", SqlDbType.Bit).Value = P.Visibilidade;
            comm.Parameters.Add("@Usuario", SqlDbType.Int).Value      = P.Usuario;
            comm.ExecuteNonQuery();
            comm.Connection.Close();
        }
示例#12
0
        // GET api/values
        public HttpResponseMessage GetPerguntas()
        {
            var perg  = new Pergunta("Cite 3 padrões de projetos.", Guid.NewGuid(), 1, DateTime.Now, true);
            var perg1 = new Pergunta("O que é MVC?", Guid.NewGuid(), 1, DateTime.Now, true);
            var list  = new List <Pergunta>();

            list.Add(perg);
            list.Add(perg1);


            return(Request.CreateResponse(HttpStatusCode.OK, list));

            //return new string[] { "value1", "value2", "value2" };
        }
        public IActionResult Post([FromBody] Pergunta pergunta)
        {
            //var perguntass = _context.Perguntas.ToList();
            //if (perguntass == null || perguntass.Count() == 0)
            //    return BadRequest();
            if (ModelState.IsValid)
            {
                _context.Perguntas.Add(pergunta);
                _context.SaveChanges();
                return(Created($"/api/perguntas/{pergunta.Id}", pergunta));
            }

            return(BadRequest(ModelState));
        }
示例#14
0
        public static Pergunta BuscarPeloId(int?id)
        {
            Pergunta ret = null;

            using (var db = new ProjectoBaseDataContext())
            {
                ret = db.Perguntas.Include(r => r.Respostas)
                      .Where(p => p.Id == id)
                      .AsNoTracking()
                      .FirstOrDefault();
            }

            return(ret);
        }
        public void SelecionarRespostaCorretaApenasUmaRespostaCadastradaComUsuarioCorreto()
        {
            Usuario usuario = new Usuario("Leonardo", "Rua Sei La", "Qualquer descrição", "https/foto.png", "*****@*****.**", "123");

            usuario.Id = 1;
            Pergunta pergunta  = new Pergunta(usuario, "Java", "Java");
            Resposta resposta1 = new Resposta(usuario, pergunta, "Java");

            pergunta.Respostas.Add(resposta1);

            Assert.IsTrue(pergunta.SelecionarRespostaCorreta(resposta1, usuario));
            Assert.IsTrue((bool)resposta1.EhRespostaCorreta);
            Assert.IsTrue(pergunta.ExisteRespostaCorreta());
        }
示例#16
0
        public IHttpActionResult DeletePergunta(int id)
        {
            Pergunta pergunta = db.Perguntas.Find(id);

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

            db.Perguntas.Remove(pergunta);
            db.SaveChanges();

            return(Ok(pergunta));
        }
        private void OcultarPerguntas(int?idAlternativa)
        {
            for (int i = 0; i < Perguntas.Count; i++)
            {
                Pergunta pergunta = Perguntas[i].Pergunta;

                if (pergunta.IdAlternativa == idAlternativa)
                {
                    Perguntas[i].Visible = false;
                }
            }

            PosicionarPerguntas();
        }
示例#18
0
        private void BtEditPerg_Click(object sender, EventArgs e)
        {
            if (lbPerguntas.SelectedItem == null)
            {
                MessageBox.Show("Para editar precisa primeiro selecionar uma das perguntas cadastradas.", Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                lbPerguntas.Focus();
                return;
            }

            _pergunta = (Pergunta)lbPerguntas.SelectedItem;
            PreencheCamposPergunta();
            lbPerguntas.Items.Remove(_pergunta);
        }
示例#19
0
        public ActionResult ExcluirPergunta(int id)
        {
            Pergunta p       = PerguntaDAO.buscarPerguntaID(id);
            int      idLicao = p.licao.idLicao;
            bool     result  = PerguntaDAO.excluirPergunta(p);

            if (result)
            {
                ViewBag.SucessoExclusao = true;
                return(RedirectToAction("VerLicao/" + idLicao, "Professor"));
            }
            ViewBag.SucessoExclusao = false;
            return(RedirectToAction("VerLicao/" + idLicao, "Professor"));
        }
        public ActionResult Edit(Pergunta p, Tema t, NivelDificuldade nd, Alternativa al)
        {
            if (Roles.IsUserInRole(User.Identity.Name, "Professor"))
            {
                ViewBag.idTema
                    = new SelectList(temaModel.todosTemas(),
                                     "idTema", "Descricao", t);

                ViewBag.idNivelDificuldade
                    = new SelectList(nivelDificuldadeModel.todosNiveisDificuldade(),
                                     "idNivelDificuldade", "Descricao", nd);

                ViewBag.Correta
                    = new SelectList(alternativaModel.obterAlternativasPorPergunta(p.idPergunta),
                                     "idAlternativa", "Descricao", al);

                if (!validarPergunta(p))
                {
                    ViewBag.Erro = "Erro na validação da Pergunta";
                    return(View(p));
                }

                string erro = null;
                if (p.idPergunta == 0)
                {
                    erro = perguntaModel.adicionarPergunta(p);
                }
                else
                {
                    erro = perguntaModel.editarPergunta(p);
                }
                if (erro == null)
                {
                    if (p.Correta == 0)
                    {
                        return(RedirectToAction("EditAlternativa", new { idAlternativa = 0, p.idPergunta }));
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    ViewBag.Erro = erro;
                    return(View(p));
                }
            }
            return(Redirect("/Shared/Restrito"));
        }
        public ActionResult Edit(int id)
        {
            if (Roles.IsUserInRole(User.Identity.Name, "Professor"))
            {
                Pergunta p = new Pergunta();
                ViewBag.Titulo = "Nova Pergunta";

                int idCurso      = 1;
                int idDisciplina = 1;

                int idTema = 1;
                int idNivelDificuldadeSelecionado = 1;
                int correta = 1;

                if (id != 0)
                {
                    p            = perguntaModel.obterPergunta(id);
                    idCurso      = p.Tema.Disciplina.idCurso;
                    idDisciplina = p.Tema.idDisciplina;
                    idTema       = p.idTema;
                    idNivelDificuldadeSelecionado = p.idNivelDificuldade;
                    correta        = p.Correta;
                    ViewBag.Titulo = "Editar Pergunta";
                }


                ViewBag.idCurso
                    = new SelectList(cursoModel.todosCursos(),
                                     "idCurso", "Descricao", idCurso);

                ViewBag.idDisciplina
                    = new SelectList(disciplinaModel.obterDisciplinaPorCurso(idCurso),
                                     "idDisciplina", "Descricao", idDisciplina);

                ViewBag.idTema
                    = new SelectList(temaModel.obterTemasPorDisciplina(idCurso),
                                     "idTema", "Descricao", idTema);

                ViewBag.idNivelDificuldade
                    = new SelectList(nivelDificuldadeModel.todosNiveisDificuldade(),
                                     "idNivelDificuldade", "Descricao", idNivelDificuldadeSelecionado);

                ViewBag.Correta
                    = new SelectList(alternativaModel.obterAlternativasPorPergunta(id),
                                     "idAlternativa", "Descricao", correta);

                return(View(p));
            }
            return(Redirect("/Shared/Restrito"));
        }
        // GET: Monitoria/Pergunta/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Pergunta pergunta = db.Perguntas.Find(id);

            if (pergunta == null)
            {
                return(HttpNotFound());
            }
            return(View(pergunta));
        }
示例#23
0
        public ActionResult IndexId(int id)
        {
            try
            {
                Pergunta pergunta = _context.Perguntas.Where(x => x.Id == id).Single();
                return(Ok(pergunta));
            }
            catch (System.Exception)
            {
                return(BadRequest());

                throw;
            }
        }
示例#24
0
        /// <summary>
        /// retorna um objeto do tipo  pergunta
        /// Juntamento com o list de imagem em ordem e o de respostas
        /// </summary>
        /// <param name="id"> parametro do tipo inteiro representando o ID da Pergunta </param>
        /// <returns></returns>
        public Pergunta Consultar(int id)
        {
            SqlCommand    comm = new SqlCommand("Select * from Pergunta where ID_Pergunta = " + id, Banco.Abrir());
            SqlDataReader dr   = comm.ExecuteReader();
            Pergunta      p    = new Pergunta();

            while (dr.Read())
            {
                p = new Pergunta
                {
                    ID           = Convert.ToInt32(dr.GetValue(0)),
                    Titulo       = dr.GetValue(1).ToString(),
                    Texto        = dr.GetValue(2).ToString(),
                    Visibilidade = Convert.ToBoolean(dr.GetValue(3)),
                    Usuario      = Convert.ToInt32(dr.GetValue(4))
                };
            }
            dr.Close();
            comm.CommandText = @"Select i.ID_Imagem,ip.Ordem_ImagemPergunta 
                                from Imagem i inner join ImagemPergunta ip 
                                on i.ID_Imagem = ip.ID_Imagem 
                                Where ip.ID_Pergunta = " + id + " order by ip.Ordem_ImagemPergunta";
            dr = comm.ExecuteReader();
            List <Imagem> listaimg = new List <Imagem>();

            while (dr.Read())
            {
                ImagemDAL dal = new ImagemDAL();
                Imagem    im  = new Imagem();
                im = dal.Consultar(Convert.ToInt32(dr.GetValue(0)));
                listaimg.Add(im);
            }
            p.Imagem = listaimg;
            dr.Close();
            comm.CommandText = "Select ID_Resposta from Resposta Where ID_Pergunta = " + id;
            dr = comm.ExecuteReader();
            List <Resposta> listresposta = new List <Resposta>();

            while (dr.Read())
            {
                Resposta    r   = new Resposta();
                RespostaDAL dal = new RespostaDAL();
                r = dal.Consultar(Convert.ToInt32(dr.GetValue(0)));
                listresposta.Add(r);
            }
            p.Resposta = listresposta;
            comm.Connection.Close();
            return(p);
        }
示例#25
0
        public IActionResult alterarPergunta([FromBody] Pergunta pergunta)
        {
            try
            {
                _context.Perguntas.Update(pergunta);
                _context.SaveChanges();
                return(Ok());
            }
            catch (System.Exception)
            {
                return(BadRequest());

                throw;
            }
        }
 public void Carregar(Pergunta pergunta)
 {
     if (pergunta.GetId() <= 0)
     {
         throw new ExcecaoSAG("Obrigatório selecionar uma pergunta.");
     }
     try
     {
         perguntaDAO.Carregar(pergunta);
     }
     catch (ExcecaoSAG ex)
     {
         throw new ExcecaoSAG(ex.getMsg());
     }
 }
示例#27
0
        public string adicionarPergunta(Pergunta p)
        {
            string erro = null;

            try
            {
                db.Pergunta.AddObject(p);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                erro = ex.Message;
            }
            return(erro);
        }
示例#28
0
        public IActionResult DesativarPergunta(int id)
        {
            if (id == 0)
            {
                TempData["MensagemErro"] = "Ocorreu um erro ao tentar desativar uma pergunta, por favor tente novamente";
                return(RedirectToAction("CadastrarPergunta", "Admin"));
            }

            TempData["MensagemSucesso"] = "Pergunta desativada com sucesso!";
            Pergunta pergunta = _perguntaRepository.ObterPerguntaPeloId(id);

            pergunta.Ativo = false;
            _perguntaRepository.Atualizar(pergunta);
            return(RedirectToAction("CadastrarPergunta", "Admin"));
        }
示例#29
0
        public string excluirPergunta(Pergunta p)
        {
            string erro = null;

            try
            {
                db.DeleteObject(p);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                erro = ex.Message;
            }
            return(erro);
        }
        // GET: /Pergunta/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Pergunta pergunta = db.Perguntas.Find(id);

            if (pergunta == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AreaJuridicaID = new SelectList(db.AreasJuridicas, "ID", "Area", pergunta.AreaJuridicaID);
            return(View(pergunta));
        }
示例#31
0
 /// <summary>
 /// Cria leiaute padrão mobile 12
 /// </summary>
 /// <returns></returns>
 public static LeiautePergunta LeiautePadrao(Pergunta p)
 {
     return(new LeiautePergunta
     {
         Pergunta = p,
         PerguntaID = p.PerguntaID,
         LeiauteItem = new HashSet <LeiautePerguntaItem> {
             new LeiautePerguntaItem
             {
                 Responsivo = eTamanhoTela.Mobile,
                 Tamanho = eColunas.T12
             }
         }
     });
 }
示例#32
0
        /// <summary>
        /// Retorna um objeto do tipo Avaliacao com a Avaliação de 1 usuario em especifico sendo, de uma resposta ou pergunta
        /// Com Pergunta, Usuario e Resposta sendo nulo ou so o ID
        /// Se o ID da Pergunta for 0 então retorna a avaliação da resposta
        /// Se o ID_Resposta for 0 então retorna a avaliação da pergunta
        /// </summary>
        /// <param name="usuario">Recebe um inteiro do ID do Usuario</param>
        /// <param name="pergunta">Recebe um inteiro do ID do Pergunta</param>
        /// <param name="resposta">Recebe um inteiro do ID da Resposta</param>
        /// <returns></returns>
        public Avaliacao Consultar(int usuario, int pergunta, int resposta)
        {
            SqlCommand comm = new SqlCommand("", Banco.Abrir());

            if (pergunta > 0)
            {
                comm.CommandText = "Select * from AvaliacaoPergunta where ID_Usuario = " + usuario + " and ID_Pergunta = " + pergunta;
            }
            else
            {
                comm.CommandText = "Select * from AvaliacaoResposta where ID_Usuario = " + usuario + " and ID_Resposta = " + resposta;
            }
            SqlDataReader dr = comm.ExecuteReader();
            Avaliacao     a  = new Avaliacao();

            while (dr.Read())
            {
                a.ID = Convert.ToInt32(dr.GetValue(0));
                Usuario u = new Usuario();
                u.ID      = Convert.ToInt32(dr.GetValue(1));
                a.Usuario = u;
                if (pergunta > 0)
                {
                    Pergunta p = new Pergunta();
                    p.ID       = Convert.ToInt32(dr.GetValue(2));
                    a.Pergunta = p;
                    a.Resposta = null;
                }
                else
                {
                    Resposta r = new Resposta();
                    r.ID       = Convert.ToInt32(dr.GetValue(2));
                    a.Pergunta = null;
                    a.Resposta = r;
                }
                if (Convert.ToBoolean(dr.GetValue(4)) == false)
                {
                    a._Avaliacao = Convert.ToBoolean(dr.GetValue(3));
                    a.Denuncia   = false;
                }
                else
                {
                    a.Denuncia = true;
                }
            }
            comm.Connection.Close();
            return(a);
        }
        public void EditarPerguntaEmExatosMenos7Dias()
        {
            Usuario  usuario  = new Usuario("Mateus", "Rua Mario Bandeira", "Costs aren't losses ", "https/foto.png", "*****@*****.**", "q1223");
            Pergunta pergunta = new Pergunta(usuario, "Java", "me ajuda");

            PropertyInfo prop = pergunta.GetType().GetProperty("DataPergunta", BindingFlags.Public | BindingFlags.Instance);

            if (prop != null && prop.CanWrite)
            {
                prop.SetValue(pergunta, DateTime.Now.AddDays(-6).AddHours(-22), null);
            }

            pergunta.Editar("teste", "teste titulo", usuario);
            Assert.AreEqual("teste titulo", pergunta.Titulo);
            Assert.AreEqual("teste", pergunta.Descricao);
        }
示例#34
0
 public PerguntaNaoRespondidaPeloUsuarioSpecification(Pergunta pergunta, Usuario usuario)
 {
     _pergunta = pergunta;
     _usuario = usuario;
 }
示例#35
0
    protected void botSavePergunta_Click(object sender, EventArgs e)
    {
        // parte geral

        // parte específica
        Pergunta selPergunta;
        selPergunta = (Pergunta)Session["selectedObject"];
        selPergunta.Name = this.txtNomePergunta.Text;
        selPergunta.TextoBase = this.txtTextoPergunta.Text;
        selPergunta.MainSortIndex = this.txtGlobalIndex.Text == "" ? -1 : int.Parse(this.txtGlobalIndex.Text);
        selPergunta.tipoPergunta = this.txtTipoPergunta.Text == "" ? null : this.txtTipoPergunta.Text;
        selPergunta.valor = this.txtValor.Text == "" ? -1 : int.Parse(this.txtValor.Text);
        selPergunta.ponderador = this.txtPonderador.Text == "" ? -1 : float.Parse(this.txtPonderador.Text);
        selPergunta.Codificacao = this.txtCodificacao.Text == "" ? null : this.txtCodificacao.Text;

        // grava na base de dados
        selPergunta.updateDBPergunta("JC");

        String mode = "";
        if (Session["mode"] != null)
            mode = (String)Session["mode"];

        modelos = (SortedList<int, ModeloCompetencias>)Session["modelos"];
        Pratica currPratica = selPergunta.Pratica;
        Competencia currCompetencia = currPratica.Competencia;
        FamiliaCompetencias currFamilia = currCompetencia.Familia;
        currModelo = modelos[currFamilia.Modelo.ModeloID];
        // actualiza a árvore de menus
        if (mode == "ADD_NEW")
        {
            TreeNode n1 = new TreeNode(selPergunta.Name, selPergunta.PerguntaID.ToString());
            ModelTree.FindNode(currModelo.ModeloID.ToString() + "|"
                                + currFamilia.FamiliaID.ToString() + "|"
                                + currCompetencia.CompetenciaID.ToString() + "|"
                                + currPratica.PraticaID.ToString()).ChildNodes.Add(n1);
            currPratica.addPergunta(selPergunta);
            currCompetencia.updatePratica(currPratica);
            currFamilia.updateCompetencia(currCompetencia);
            currModelo.updateFamilia(currFamilia);
            Session.Remove("mode");
            n1.Select();
            //n1.Expand();
        }
        else
        {
            TreeNode theNode = ModelTree.FindNode(currModelo.ModeloID.ToString() + "|"
                                                + currFamilia.FamiliaID.ToString() + "|"
                                                + currCompetencia.CompetenciaID.ToString() + "|"
                                                + currPratica.PraticaID.ToString() + "|"
                                                + selPergunta.PerguntaID.ToString());
            theNode.Text = selPergunta.Name;
            currPratica.updatePergunta(selPergunta);
            currCompetencia.updatePratica(currPratica); // actualiza a lista de pratica da competência
            currFamilia.updateCompetencia(currCompetencia); // actualiza a lista de competencias na família
            currModelo.updateFamilia(currFamilia); // actualiza a lista de famílias no modelo
        }
        Session["modelos"] = modelos;
        Session["currModelo"] = currModelo;
        Session["selectedObject"] = selPergunta;

        // actualiza o preview da pegunta

        this.txtNomePergunta.Text = Context.Server.HtmlDecode(selPergunta.Name);
        this.txtTextoPergunta.Text = Context.Server.HtmlDecode(selPergunta.TextoBase);

        Pessoa p1 = new Pessoa();
        p1.NomeProprio = "Joana";
        p1.NomesMeio = "dos Santos";
        p1.Apelido = "Marques";
        p1.Sexo = "F";
        p1.Email = "aaa";

        Pessoa p2 = new Pessoa();
        p2.NomeProprio = "Vasco";
        p2.NomesMeio = "Manuel";
        p2.Apelido = "Carvalho";
        p2.Sexo = "M";
        p2.Email = "bbb";

        Pessoa p3 = new Pessoa();
        p3.NomeProprio = "Marco";
        p3.NomesMeio = "António";
        p3.Apelido = "Curto";
        p3.Sexo = "M";
        p3.Email = "ccc";

        Pergunta perg = new Pergunta(selPergunta.TextoBase);
        perg.setupPergunta(p1, p1,false);
        this.lblAutoavaliacao.Text = "<p>" + Context.Server.HtmlDecode(perg.GetPerguntaText()) + "</p>";
        Pessoa[] grupo = { p1, p3 };

        perg.setupPergunta(p2, grupo, false);
        this.lblGrupo.Text = "<p>" + Context.Server.HtmlDecode(perg.GetPerguntaText()) + "</p>";

        perg.setupPergunta(p2, p1, false);
        this.lblJoana.Text = "<p>" + Context.Server.HtmlDecode(perg.GetPerguntaText()) + "</p>";

        perg.setupPergunta(p3, p2, false);
        this.lblVasco.Text = "<p>" + Context.Server.HtmlDecode(perg.GetPerguntaText()) + "</p>";
    }
示例#36
0
    protected void addNewPergunta()
    {
        ModeloCompetencias currModelo;
        FamiliaCompetencias currFamilia;
        Competencia currCompetencia;
        Pratica currPratica;
        Pergunta novaPergunta;

        currPratica = (Pratica)Session["selectedObject"]; ;
        currCompetencia = currPratica.Competencia;
        currFamilia = currCompetencia.Familia;
        currModelo = currFamilia.Modelo;

        novaPergunta = new Pergunta(currPratica);
        selectedObject = novaPergunta;
        Session["selectedObject"] = selectedObject;
        Session.Add("mode", "ADD_NEW");

        View selView;

        selView = PerguntaView;
        if (selView != null)
        {
            MView.SetActiveView(selView);
        }
        else
        {
            MView.Visible = false;
            commonDataFieldsTable.Visible = false;
        }
        updateCommonFields();
        updateSpecialFields();
    }
示例#37
0
    protected void updateSpecialFields()
    {
        object theObject;

        if (Session["selectedObject"] == null)
        {
            this.commonDataFieldsTable.Visible = false;
            return;
        }

        commonDataFieldsTable.Visible = true;

        theObject = Session["selectedObject"];

        if (theObject.GetType() == typeof(ModeloCompetencias))
        {
            ModeloCompetencias selObject;
            selObject = (ModeloCompetencias)Session["selectedObject"];
            txtModeloEscala.Text = selObject.Scale;
            txtModeloEscalaDesc.Text = Server.HtmlDecode(selObject.ScaleDesc);
            txtTipoModelo.Text = selObject.ModelType;
            this.chkNR_Modelo.Checked = selObject.NR == null ? false : selObject.NR;
        }
        else if (theObject.GetType() == typeof(FamiliaCompetencias))
        {

        }
        else if (theObject.GetType() == typeof(Competencia))
        {

            Competencia selObject;
            selObject = (Competencia)Session["selectedObject"];
            this.txtCriticCompEscala.Text = Server.HtmlDecode(selObject.CriticalidadeScale);
            this.txtCriticCompDescrEscala.Text = Server.HtmlDecode(selObject.CriticalidadeText);
            this.chkCriticCompetencia.Checked = selObject.Criticalidade;
            this.txtType.Text = selObject.Type;
            this.chkNR_Criticalidade.Checked = selObject.NR == null ? false : selObject.NR;
            this.chkOpcional.Checked = selObject.Opcional == null ? false : selObject.Opcional;
        }
        else if (theObject.GetType() == typeof(Pratica))
        {

            Pratica selObject;
            selObject = (Pratica)Session["selectedObject"];
            this.txtCriticPratEscala.Text = Server.HtmlDecode(selObject.CriticalidadeScale);
            this.txtCriticPratDescrEscala.Text = Server.HtmlDecode(selObject.CriticalidadeText);
            this.chkCriticPratica.Checked = selObject.Criticalidade;
            this.chkNR.Checked = selObject.NR;

        }
        else if (theObject.GetType() == typeof(Pergunta))
        {
            commonDataFieldsTable.Visible = false;
            Pergunta selObject;
            selObject = (Pergunta)Session["selectedObject"];

            this.txtNomePergunta.Text = selObject.Name;
            this.txtTextoPergunta.Text = selObject.TextoBase;
            this.txtGlobalIndex.Text = selObject.MainSortIndex.ToString();
            this.txtTipoPergunta.Text = selObject.tipoPergunta;
            this.txtValor.Text = selObject.valor == 0 ? "-1" :  selObject.valor.ToString();
            this.txtPonderador.Text = selObject.ponderador == 0 ? "-1" : selObject.ponderador.ToString();
            this.txtCodificacao.Text = selObject.Codificacao;

            Pessoa p1 = new Pessoa();
            p1.NomeProprio = "Joana";
            p1.NomesMeio = "dos Santos";
            p1.Apelido = "Marques";
            p1.Sexo = "F";
            p1.Email = "aaa";

            Pessoa p2 = new Pessoa();
            p2.NomeProprio = "Vasco";
            p2.NomesMeio = "Manuel";
            p2.Apelido = "Carvalho";
            p2.Sexo = "M";
            p2.Email = "bbb";

            Pessoa p3 = new Pessoa();
            p3.NomeProprio = "Marco";
            p3.NomesMeio = "António";
            p3.Apelido = "Curto";
            p3.Sexo = "M";
            p3.Email = "ccc";

            Pergunta perg = new Pergunta(selObject.TextoBase);
            perg.setupPergunta(p1, p1, false);
            this.lblAutoavaliacao.Text = "<p>" + perg.GetPerguntaText() + "</p>";
            Pessoa[] grupo = { p1, p3 };

            perg.setupPergunta(p2, grupo, false);
            this.lblGrupo.Text = "<p>" + perg.GetPerguntaText() + "</p>";

            perg.setupPergunta(p2, p1, false);
            this.lblJoana.Text = "<p>" + perg.GetPerguntaText() + "</p>";

            perg.setupPergunta(p3, p2, false);
            this.lblVasco.Text = "<p>" + perg.GetPerguntaText() + "</p>";
        }
    }
示例#38
0
    protected void Page_Load(object sender, EventArgs e)
    {
        txtErrorMessage = "";
        dic = Utility.theDictionary;
        ScriptManager.RegisterStartupScript(this, typeof(String), "langValidation", Utility.validationJSLib, false);
        Utility.currType = Type;
        MultiVistasModel.Visible = false;
        Title = dic.getResource(219);
        if (!IsPostBack)
            setupInicialForm();
        else
        {

            // analisa os postbacks
            switch (Mode)
            {
                case "MoveToAccount":
                    if (Utility.currModelo != null)
                    {
                        moveModelToAccount(DDLAccountsTOMove.SelectedValue);
                    }

                    break;
                case "Model":
                    if (Utility.currType.Equals("Edit"))
                    {
                        MultiVistasModel.Visible = true;
                        MultiVistasModel.ActiveViewIndex = 0;
                        updateEditorFields();
                    }
                    else if (Utility.currType.Equals("List"))
                    {
                        Utility.currModelo = null;
                        setupInicialForm();
                    }
                    else if (Utility.currType.Equals("SaveModelConfig"))
                    {
                        saveEditModelo();
                        MultiVistasModel.Visible = false;
                        setupInicialForm();
                        Utility.currType = "";
                    }
                    else if (Utility.currType.Equals("Delete"))
                    {
                        if (Utility.currModelo.ModelInUse() == 0)
                        {
                            if (Utility.currModelo.DeleteFromDB())
                            {
                                Utility.messageBox(this, dic.getResource(225), dic.getResource(339), false);
                            }
                            else
                            {
                                Utility.messageErrorBox(this, dic.getResource(225), dic.getResource(340), true);
                                //txtErrorMessage = dic.getResource(340);
                            }
                        }
                        else
                        {
                            Utility.messageErrorBox(this, dic.getResource(225), dic.getResource(400), true);
                        }
                        Utility.currModelo = null;
                        setupInicialForm();
                        Utility.currType = "";
                    }
                    else if (Utility.currType.StartsWith("Edit="))
                    {
                        int ModelID;
                        String[] args = Utility.currType.Split('=');
                        int.TryParse(args[1], out ModelID);
                        selectModel(ModelID);
                        MultiVistasModel.Visible = true;
                        MultiVistasModel.ActiveViewIndex = 0;
                        updateEditorFields();
                    }
                    else if (Utility.currType.StartsWith("Delete="))
                    {
                        int ModelID;
                        String[] args = Utility.currType.Split('=');
                        int.TryParse(args[1], out ModelID);
                        selectModel(ModelID);
                        if (Utility.currModelo != null)
                        {
                            if (Utility.currModelo.ModelInUse() == 0)
                            {
                                if (Utility.currModelo.DeleteFromDB())
                                {
                                    Utility.messageBox(this, dic.getResource(225), dic.getResource(339), false);
                                }
                                else
                                {
                                    Utility.messageErrorBox(this, dic.getResource(225), dic.getResource(340), true);
                                    //txtErrorMessage = dic.getResource(340);
                                }
                            }
                            else
                            {
                                Utility.messageErrorBox(this, dic.getResource(225), dic.getResource(400), true);
                            }

                        }
                        Utility.currModelo = null;
                        setupInicialForm();
                        Utility.currType = "";
                    }
                    else if (Utility.currType.StartsWith("Select="))
                    {
                        int ModelID;
                        String[] args = Utility.currType.Split('=');
                        int.TryParse(args[1], out ModelID);
                        selectModel(ModelID);
                    }
                    break;
                case "CompSelect":
                    compSelected();
                    break;
                case "CompEdit":
                    compEdit();
                    break;
                case "CompDelete":
                    if (Utility.currCompetencia.eraseCompetencia())
                    {
                        Utility.currModelo = ModeloCompetencias.getDBModelo(Utility.currModelo.owner, Utility.currModelo.ModeloID);
                        Utility.currModelo.loadFull(Utility.currModelo.owner, null);
                        Utility.messageBox(this, dic.getResource(225), dic.getResource(343), false);
                    }
                    else
                        Utility.messageErrorBox(this, dic.getResource(225), "Undifined Error!!", true);
                    // txtErrorMessage = "Erro !";

                    Utility.currCompetencia = null;
                    setupInicialForm();
                    break;
                case "Add":
                    if (Type.Equals("Pergunta"))
                    {
                        Pergunta novaP = new Pergunta(Utility.currCompetencia.Praticas.FirstOrDefault().Value);
                        novaP.Name = "...";
                        novaP.updateDBPergunta(Utility.currModelo.owner);
                        Utility.currModelo = ModeloCompetencias.getDBModelo(Utility.currModelo.owner, Utility.currModelo.ModeloID);
                        Utility.currModelo.loadFull(Utility.currModelo.owner, null);
                        compEdit();
                    }
                    break;
                case "CompSave":
                    saveCompetencia();
                    savePerguntas();
                    Mode = "CompSelect";
                    int famID_ = Utility.currCompetencia.Familia.FamiliaID;
                    int compID_ = Utility.currCompetencia.CompetenciaID;
                    Utility.currType = famID_.ToString() + "_" + compID_.ToString();
                    compSelected();

                    break;
                case "Pergunta":
                    if (Type.StartsWith("Delete="))
                    {
                        Type = Type.Replace("Delete=", "");
                        Pergunta.deleteDBPergunta(int.Parse(Type));
                        Utility.currModelo = ModeloCompetencias.getDBModelo(Utility.currModelo.owner, Utility.currModelo.ModeloID);
                        Utility.currModelo.loadFull(Utility.currModelo.owner, null);
                        compEdit();
                    }
                    break;
            }
        }

        if ((Utility.theUser.owner == "JC" && Utility.currModelo != null) || (Utility.theUser.owner == "TEMPLATE" && Utility.currModelo != null))
        {
            TEMPLATE_CONVERTER.Visible = true;
            SetupDDLAccountsTOMove();
            modeloIDDiv.InnerHtml = "Modelo ID:" + Utility.currModelo.ModeloID.ToString();

        }
        else
        {
            modeloIDDiv.InnerHtml = "";
            TEMPLATE_CONVERTER.Visible = false;
        }

        if (CompEDIT_1.Visible) CompEDIT_1.Visible = Utility.theUser.AccessMenu(Utility.MODELS, Utility.READ_EDIT);
        if (CompDELETE_1.Visible) CompDELETE_1.Visible = Utility.theUser.AccessMenu(Utility.MODELS, Utility.READ_EDIT_CREATE_DELETE);
    }
示例#39
0
 public RespostaCorretaSpecification(Pergunta perguntaRespondida, Resposta respostaSugerida)
 {
     _respostaSugerida = respostaSugerida;
     _perguntaRespondida = perguntaRespondida;
 }