public ActionResult GetWebhookResponse2([FromBody] System.Text.Json.JsonElement dados)
        {
            if (!Autorizado(Request.Headers))
            {
                return(StatusCode(401));
            }

            WebhookRequest request =
                _jsonParser.Parse <WebhookRequest>(dados.GetRawText());

            WebhookResponse response = new WebhookResponse();


            if (request != null)
            {
                string action = request.QueryResult.Action;

                if (action == "ActionTesteWH")
                {
                    response.FulfillmentText = "testando o webhook 2";
                }
            }

            return(Ok(response));
        }
コード例 #2
0
        public static System.String GetCorrectColumnValue(System.Text.Json.JsonElement JsonElement)
        {
            switch (JsonElement.ValueKind)
            {
            case System.Text.Json.JsonValueKind.Array:
            case System.Text.Json.JsonValueKind.Object:
                return(System.String.Concat("'", JsonElement.GetRawText().Replace("'", "''"), "'"));

            case System.Text.Json.JsonValueKind.String:
                return(System.String.Concat("'", JsonElement.GetString().Replace("'", "''"), "'"));

            case System.Text.Json.JsonValueKind.True:
            case System.Text.Json.JsonValueKind.False:
                return(System.Convert.ToInt32(JsonElement.GetBoolean()).ToString());

            case System.Text.Json.JsonValueKind.Number:
                return(JsonElement.GetRawText());

            default:
                return("NULL");
            }
        }
コード例 #3
0
ファイル: UserController.cs プロジェクト: CESAR1102/GPWPRW
 public ActionResult UpdatePassword([FromBody] System.Text.Json.JsonElement entity)
 {
     try
     {
         User user = JsonConvert.DeserializeObject <User>(entity.GetRawText().ToString());
         return(Ok(userService.UpdatePassword(user)));
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
     return(Ok(false));
 }
コード例 #4
0
        static StackObject *GetRawText_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);
            System.Text.Json.JsonElement instance_of_this_method = (System.Text.Json.JsonElement) typeof(System.Text.Json.JsonElement).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 16);

            var result_of_this_method = instance_of_this_method.GetRawText();

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            WriteBackInstance(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method);

            __intp.Free(ptr_of_this_method);
            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
コード例 #5
0
ファイル: DeckController.cs プロジェクト: DaneArt/MyDeckAPI
        public async Task <IActionResult> Update([FromBody] System.Text.Json.JsonElement value)
        {
            Deck deck = JsonConvert.DeserializeObject <Deck>(value.GetRawText());

            logger.LogInformation("------------> Deck have been converted <------------");
            var content = await updateDeckUseCase.Invoke(new UpdateDeckParams(deck));

            logger.LogInformation($@"------------>UDeckUseCase returned result: {content} <------------");
            if (content == 0)
            {
                logger.LogInformation("------------> Deck/s have been updated <------------");
                return(Ok());
            }
            else
            {
                logger.LogInformation("------------> Deck have not been updated <------------");
                return(BadRequest());
            }
        }
コード例 #6
0
        public async Task <IActionResult> SignInWithUsername([FromBody] System.Text.Json.JsonElement usr)
        {
            try
            {
                string sessionId;
                Request.Cookies.TryGetValue("sessionId", out sessionId);
                if (sessionId == null)
                {
                    throw new Exception("Empty SessionId");
                }
                var user     = JsonConvert.DeserializeObject <AuthUserModel>(usr.GetRawText());
                var response = await authFacade.SignInWithUsername(user.UserName, user.Password, Guid.Parse(sessionId));

                return(Ok(response));
            }
            catch (Exception ex)
            {
                logger.LogWarning("------------> An error has occurred <------------ \n" + ex.Message);
                return(BadRequest(ex.Message));
            }
        }
コード例 #7
0
ファイル: DeckController.cs プロジェクト: DaneArt/MyDeckAPI
        public async Task <IActionResult> Insert([FromBody] System.Text.Json.JsonElement value)
        {
            try
            {
                Deck deck = JsonConvert.DeserializeObject <Deck>(value.GetRawText());


                await deckRepository.Insert(deck);

                await userDeckRepository.Insert(
                    new UserDeck { User_Id = Guid.Parse(deck.Author), Deck_Id = deck.Deck_Id });

                deckRepository.Save();

                logger.LogInformation("------------> Deck/s have been added <------------");
                return(Ok());
            }
            catch (Exception ex)
            {
                logger.LogWarning("------------> An error has occurred <------------ \n" + ex.Message);
                return(BadRequest(ex.Message));
            }
        }
        public ActionResult GetWebhookResponse([FromBody] System.Text.Json.JsonElement dados)
        {
            if (!Autorizado(Request.Headers))
            {
                return(StatusCode(401));
            }

            WebhookRequest request =
                _jsonParser.Parse <WebhookRequest>(dados.GetRawText());

            WebhookResponse response = new WebhookResponse();


            if (request != null)
            {
                string action     = request.QueryResult.Action;
                var    parameters = request.QueryResult.Parameters;

                if (action == "ActionTesteWH")
                {
                    response.FulfillmentText = "testando o webhook 2";
                }
                else if (action == "ActionCursoOferta")
                {
                    DAL.CursoDAL dal = new DAL.CursoDAL();

                    if (parameters != null &&
                        parameters.Fields.ContainsKey("Cursos"))
                    {
                        var cursos = parameters.Fields["Cursos"];

                        if (cursos != null && cursos.ListValue.Values.Count > 0)
                        {
                            string curso = cursos.ListValue.Values[0].StringValue;
                            if (dal.ObterCurso(curso) != null)
                            {
                                response.FulfillmentText = "Sim, temos " + curso + ".";
                            }
                        }
                        else
                        {
                            response.FulfillmentText = "Não temos, mas temos esses: " + dal.ObterTodosFormatoTexto() + ".";
                        }
                    }
                }
                else if (action == "ActionCursoValor")
                {
                    var contexto = request.QueryResult.OutputContexts;

                    if (contexto[0].ContextName.ContextId == "ctxcurso")
                    {
                        if (contexto[0].Parameters != null &&
                            contexto[0].Parameters.Fields.ContainsKey("Cursos"))
                        {
                            var          cursos = contexto[0].Parameters.Fields["Cursos"];
                            string       curso  = cursos.ListValue.Values[0].StringValue;
                            DAL.CursoDAL dal    = new DAL.CursoDAL();

                            Models.Curso c = dal.ObterCurso(curso);
                            if (c != null)
                            {
                                response.FulfillmentText =
                                    "A mensalidade para " + c.Nome + " é " + c.Preco + ".";
                            }
                        }
                    }
                }

                else if (action == "ActionTesteWHPayload")
                {
                    var contexto = request.QueryResult.OutputContexts;

                    var payload = "{\"list\": {\"replacementKey\": \"@contexto\",\"invokeEvent\": true,\"afterDialog\": true,\"itemsName\": [\"Sim\",\"Não\"],\"itemsEventName\": [\"QueroInscrever\",\"NaoQueroInscrever\"]}}";


                    response = new WebhookResponse()
                    {
                        FulfillmentText = "Teste Payload no WH com sucesso...",
                        Payload         = Google.Protobuf.WellKnownTypes.Struct.Parser.ParseJson(payload)
                    };
                }
            }

            return(Ok(response));
        }
コード例 #9
0
        public ActionResult GetWebhookResponse([FromBody] System.Text.Json.JsonElement dados)
        {
            if (!Autorizado(Request.Headers))
            {
                return(StatusCode(401));
            }

            WebhookRequest request =
                _jsonParser.Parse <WebhookRequest>(dados.GetRawText());

            WebhookResponse response = new WebhookResponse();

            if (request != null)
            {
                //Obtem o id da sesão do dialogflow
                this.Sessao.Id = this.getIdSession(request.QueryResult.OutputContexts[0].Name);
                this.Sessao.Recover();

                string action     = request.QueryResult.Action;
                var    parameters = request.QueryResult.Parameters;

                try
                {
                    Models.Candidato candidato = new Models.Candidato();
                    candidato.CarregarBase();
                    Models.Curso curso = new Models.Curso();

                    if (action == "ActionInformaCPF")
                    {
                        var cpf = parameters.Fields["cpf"].StringValue;

                        if (cpf.Length > 11)
                        {
                            response.FulfillmentText = "CPF é inválido " + cpf;
                        }
                        else
                        {
                            //procurar CPF na base de dados
                            cpf       = cpf.Replace(".", "");
                            cpf       = cpf.Replace("-", "");
                            candidato = candidato.ObterCandidato(cpf);
                            //gravao cpf na sessao
                            this.Sessao.Add("cpf", cpf);

                            if (candidato != null)
                            {
                                this.Sessao.Add("logado", "1");
                                response.FulfillmentText = "Olá " + candidato.Nome + ". Encontrei sua inscrição, " + this.Menu();
                            }
                            else
                            {
                                this.Sessao.Add("logado", "0");
                                response.FulfillmentText = "Não foi possível encontrar seus dados, qual o seu nome?";
                            }
                            this.Sessao.Save();
                        }
                    }
                    else if (action == "ActionInformaNome")
                    {
                        if (this.Sessao.Get("logado") == "0")
                        {
                            this.Sessao.Add("nome", parameters.Fields["nome"].StringValue);
                            this.Sessao.Save();
                            response.FulfillmentText = "Qual o seu email?";
                        }
                    }
                    else if (action == "ActionInformaEmail")
                    {
                        if (this.Sessao.Get("logado") == "0")
                        {
                            string email = parameters.Fields["email"].StringValue;

                            if (candidato.EmailIsvalid(email))
                            {
                                this.Sessao.Add("email", email);
                                this.Sessao.Save();
                                var rcursos  = curso.ObterTodos();
                                var mensagem = "Qual Curso Deseja ? <br/><ul>";

                                foreach (var item in rcursos)
                                {
                                    mensagem += "<li><a href=\"javascript:BOT.InfCurso('" + item.Nome + "', '" + item.Url + "');\">" + item.Nome + "</a></li>";
                                }
                                mensagem += "</ul>";
                                response.FulfillmentText = mensagem;
                            }
                            else
                            {
                                response.FulfillmentText = "Informe um email válido!";
                            }
                        }
                    }
                    else if (action == "ActionInformaCurso")
                    {
                        curso = curso.Obter(parameters.Fields["curso"].StringValue);
                        if (curso != null)
                        {
                            this.Sessao.Add("curso", curso.Nome);
                            this.Sessao.Save();
                            response.FulfillmentText = "Vi que você não é um candidato. <a href=\"javascript: BOT.Gravar();\">Clique aqui para se inscrever</a> ou me pergunte alguma coisa.";
                        }
                        else
                        {
                            response.FulfillmentText = "Curso não encontrado!";
                        }
                    }
                    else if (action == "ActionCadastrar")
                    {
                        curso = curso.Obter(this.Sessao.Get("curso"));
                        candidato.Setar(this.Sessao.Get("nome"), this.Sessao.Get("cpf"), this.Sessao.Get("email"), curso);

                        if (candidato.Gravar())
                        {
                            this.Sessao.Add("logado", "1");
                            response.FulfillmentText = "Olá " + candidato.Nome + " sua inscrição foi realizada com sucesso!" + this.Menu();
                        }
                        else
                        {
                            response.FulfillmentText = "Desculpe não foi possível realizar cadastro :(, por favor tente novamente mais tarde.";
                        }
                    }
                    else if (action == "ActionMenu")
                    {
                        if (this.Sessao.Get("logado") == "1")
                        {
                            response.FulfillmentText = this.Menu();
                        }
                    }
                    else if (action == "ActionObterDadosCadastrais")
                    {
                        if (this.Sessao.Get("logado") == "1")
                        {
                            candidato = candidato.ObterCandidato(this.Sessao.Get("cpf"));
                            response.FulfillmentText = "Informações cadastrais: <br/>" +
                                                       "Nome: " + candidato.Nome + "<br/>" +
                                                       "CPF: " + candidato.CPF + "<br/>" +
                                                       "Email:" + candidato.Email + " <br/>" +
                                                       "Vestibulando curso: " + candidato.Curso.Nome + " <br/>";
                        }
                    }
                    else if (action == "ActionObterResultadoVestibular")
                    {
                        if (this.Sessao.Get("logado") == "1")
                        {
                            candidato = candidato.ObterCandidato(this.Sessao.Get("cpf"));
                            if (candidato.ResVestibular == 1)
                            {
                                response.FulfillmentText = "Foi aprovado no vestibular :)";
                            }
                            else if (candidato.ResVestibular == 0)
                            {
                                response.FulfillmentText = "O resultado ainda não saiu :(";
                            }
                            else if (candidato.ResVestibular == -1)
                            {
                                response.FulfillmentText = "Infelizmente você foi reprovado na primeira chamada :(";
                            }
                        }
                    }
                    else if (action == "ActionObterNumeroAlunosMatriculados")
                    {
                        if (this.Sessao.Get("logado") == "1")
                        {
                            candidato = candidato.ObterCandidato(this.Sessao.Get("cpf"));
                            response.FulfillmentText = "O número de inscritos para o curso de " + candidato.Curso.Nome + " foi de " + candidato.Curso.NumeroInscritos + " incrições.";
                        }
                    }
                }
                catch (Exception ex)
                {
                    response.FulfillmentText = "Erro: " + ex.Message.ToString();
                }
            }

            return(Ok(response));
        }
コード例 #10
0
 private static WebhookRequest ObterRequest(System.Text.Json.JsonElement dados)
 {
     return(_jsonParser.Parse <WebhookRequest>(dados.GetRawText()));
 }