コード例 #1
0
        public ActionResult NovaPerguntaVinculada(string UKT, string UKP)
        {
            Guid UKTipoRespostaItem = Guid.Parse(UKT);
            Guid UKPerg             = Guid.Parse(UKP);

            TipoRespostaItem oTipoRespItem = TipoRespostaItemBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.UniqueKey.Equals(UKTipoRespostaItem));
            Pergunta         oPergunta     = PerguntaBusiness.Consulta.FirstOrDefault(a => string.IsNullOrEmpty(a.UsuarioExclusao) && a.UniqueKey.Equals(UKPerg));

            VMNovaPerguntaVinculada obj = new VMNovaPerguntaVinculada()
            {
                PerguntaVinculada         = oPergunta,
                TipoRespostaItemVinculada = oTipoRespItem,
            };

            ViewBag.TiposDeRespostas = TipoRespostaBusiness.Consulta.Where(a => string.IsNullOrEmpty(a.UsuarioExclusao)).OrderBy(a => a.Nome).ToList();

            return(View(obj));
        }
コード例 #2
0
        public ActionResult CadastrarVinculada(VMNovaPerguntaVinculada entidade)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (entidade.PerguntaVinculada == null || entidade.PerguntaVinculada.UniqueKey == null || entidade.PerguntaVinculada.UniqueKey == Guid.Empty)
                    {
                        throw new Exception("Não foi possível localizar a pergunta vinculada a pergunta a ser cadastrada.");
                    }

                    if (entidade.TipoRespostaItemVinculada == null || entidade.TipoRespostaItemVinculada.UniqueKey == null || entidade.TipoRespostaItemVinculada.UniqueKey == Guid.Empty)
                    {
                        throw new Exception("Não foi possível localizar a resposta vinculada a pergunta a ser cadastrada.");
                    }

                    if (string.IsNullOrEmpty(entidade.Descricao))
                    {
                        throw new Exception("Informe a pergunta antes de prosseguir com a criação.");
                    }

                    if (entidade.TipoResposta == GISModel.Enums.ETipoResposta.Multipla_Selecao || entidade.TipoResposta == GISModel.Enums.ETipoResposta.Selecao_Unica)
                    {
                        if (entidade.UKTipoResposta == null || entidade.UKTipoResposta == Guid.Empty)
                        {
                            throw new Exception("Não foi possível localizar as possíveis respostas para a pergunta de múltipla escolha a ser cadastrada.");
                        }
                    }


                    Pergunta oPergunta = new Pergunta()
                    {
                        UniqueKey       = Guid.NewGuid(),
                        Descricao       = entidade.Descricao,
                        TipoResposta    = entidade.TipoResposta,
                        UKTipoResposta  = entidade.UKTipoResposta,
                        Ordem           = entidade.Ordem,
                        UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login
                    };
                    PerguntaBusiness.Inserir(oPergunta);



                    REL_PerguntaTipoRespostaItem oRel = new REL_PerguntaTipoRespostaItem()
                    {
                        UKPerguntaVinculada = entidade.PerguntaVinculada.UniqueKey,
                        UKTipoRespostaItem  = entidade.TipoRespostaItemVinculada.UniqueKey,
                        UKNovaPergunta      = oPergunta.UniqueKey,
                        UsuarioInclusao     = CustomAuthorizationProvider.UsuarioAutenticado.Login
                    };

                    REL_PerguntaTipoRespostaItemBusiness.Inserir(oRel);



                    Extensions.GravaCookie("MensagemSucesso", "A pergunta vinculada foi cadastrada com sucesso.", 10);

                    return(Json(new { resultado = new RetornoJSON()
                                      {
                                          URL = Url.Action("Index", "Questionario")
                                      } }));
                }
                catch (Exception ex)
                {
                    if (ex.GetBaseException() == null)
                    {
                        return(Json(new { resultado = new RetornoJSON()
                                          {
                                              Erro = ex.Message
                                          } }));
                    }
                    else
                    {
                        return(Json(new { resultado = new RetornoJSON()
                                          {
                                              Erro = ex.GetBaseException().Message
                                          } }));
                    }
                }
            }
            else
            {
                return(Json(new { resultado = TratarRetornoValidacaoToJSON() }));
            }
        }