Пример #1
0
        private void btnAddResponse_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (var item in _respostas)
                {
                    if (item.CorpoResposta == txtResposta.Text)
                    {
                        throw new DuplicadaException(String.Format("Resposta duplicada"));
                    }
                }

                labelStatus.Text = "";
                Resposta res = new Resposta();
                res.CorpoResposta = txtResposta.Text;
                res.Correta       = ckbCorreta.Checked;
                res.Validar();
                _respostasAdicionadas.Add(res);
                _respostas.Add(res);

                txtResposta.Text   = "";
                ckbCorreta.Checked = false;
                _userControlRespostas.PopularListagem(_respostas);
            }
            catch (DuplicadaException ex)
            {
                labelStatus.Text = ex.Message;
            }
            catch (Exception ex)
            {
                labelStatus.Text = ex.Message;
            }
        }
Пример #2
0
        public RespostaModeloDeFormulario GravarRespostaModeloFormulario(RespostaModeloFormularioDTO respostaModeloDTO, string UsuarioID)
        {
            using (var repo = factory.Get().GetRepository <Resposta>())
                using (var repoRespostaModelo = factory.Get().GetRepository <RespostaModeloDeFormulario>())
                    using (var repoPergunta = factory.Get().GetRepository <Pergunta>())
                    {
                        var respostaModeloFormulario = BuscarRespostaModeloDeFormulario().SingleOrDefault(c => c.RespostaModeloFormularioID == respostaModeloDTO.RespostaModeloFormularioID);

                        if (respostaModeloFormulario == null)
                        {
                            respostaModeloFormulario = repoRespostaModelo.Insert(new RespostaModeloDeFormulario());
                        }

                        respostaModeloFormulario.ModeloDeFormularioID = respostaModeloDTO.ModeloFormulario.ModeloFormularioID;

                        respostaModeloFormulario.ControleAtualizacao = ControleUsuario.Criar(UsuarioID);

                        foreach (var respostaDTO in respostaModeloDTO.Respostas.OrderBy(c => c.PerguntaID).ToList())
                        {
                            //RespostaTexto
                            var      pergunta = respostaModeloDTO.ModeloFormulario.Perguntas.Single(c => c.PerguntaID == respostaDTO.PerguntaID);
                            Resposta resposta = BuscarResposta().SingleOrDefault(c => c.RespostaID == respostaDTO.RespostaID);
                            if (resposta == null)
                            {
                                resposta = repo.Insert(CriarResposta(respostaDTO, pergunta.TipoPergunta));
                            }
                            else
                            {
                                resposta.AtribuirResposta(respostaDTO);
                            }

                            resposta.Pergunta = repoPergunta.GetQuery().Single(d => d.PerguntaID == resposta.PerguntaID);
                            resposta.RespostaModeloDeFormulario = respostaModeloFormulario;
                            resposta.ControleAtualizacao        = ControleUsuario.Criar(UsuarioID);

                            respostaModeloFormulario.Respostas.Add(resposta);
                        }

                        foreach (var resposta in respostaModeloFormulario.Respostas)
                        {
                            bool validarResposta = true;

                            if (resposta.Pergunta.PerguntaCondicionalID.HasValue)
                            {
                                var respostaOrigem = respostaModeloFormulario.Respostas.Single(d => d.PerguntaID == resposta.Pergunta.PerguntaCondicional.PerguntaID);

                                validarResposta = resposta.Pergunta.PerguntaCondicional.ValidarCondicional(respostaOrigem);
                            }

                            if (validarResposta && resposta.Validar() == false)
                            {
                                throw new ApplicationException($"Verifique a resposta da pergunta {resposta.Pergunta.PerguntaID} {resposta.Pergunta.Titulo}");
                            }
                        }

                        return(respostaModeloFormulario);
                    }
        }