public async System.Threading.Tasks.Task <ActionResult> Vote(int id, VO_View viewModel)
        {
            Baseurl = Baseurl + viewModel.id + "/vote";
            try
            {
                // TODO: Add update logic here
                var handler = new WebRequestHandler();
                handler.ServerCertificateValidationCallback = delegate { return(true); };
                using (HttpClient votoUi = new HttpClient(handler))
                {
                    votoUi.BaseAddress = new Uri(Baseurl);
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
                    var resposta = await votoUi.GetAsync("");

                    VO_Voto voto = new VO_Voto();
                    voto.option_id = viewModel.option_vote;
                    var serializedVoto = JsonConvert.SerializeObject(voto);
                    var content        = new StringContent(serializedVoto, Encoding.UTF8, "application/json");

                    var result = await votoUi.PostAsync(Baseurl, content);
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #2
0
        public void Vote(int id, [FromBody] VO_Voto voto)
        {
            Enquete  cadEnquete = new Enquete();
            TB_Opcao opcao      = new TB_Opcao();

            opcao.poll_id = id;
            if (voto.option_id > 3 || voto.option_id < 1)
            {
                voto.option_id = 1;
            }
            opcao.option_id = voto.option_id;
            cadEnquete.Votar(opcao);
        }