//********************Voto********************\\ // GET: Poll/Edit/5 public async System.Threading.Tasks.Task <ActionResult> Vote(int id) { //TB_Enquete Listar = null; VO_Enquete Listar2 = null; List <VO_View> ListarTodosView = new List <VO_View> { }; try { var handler = new WebRequestHandler(); handler.ServerCertificateValidationCallback = delegate { return(true); }; using (HttpClient votoUi = new HttpClient(handler)) { votoUi.BaseAddress = new Uri(Baseurl + id); ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; var resposta = await votoUi.GetAsync(""); string dados = await resposta.Content.ReadAsStringAsync(); Listar2 = new JavaScriptSerializer().Deserialize <VO_Enquete>(dados); } VO_View viewModel = new VO_View(); viewModel.id = Listar2.poll_id; viewModel.description = Listar2.poll_description; viewModel.option_1 = Listar2.options[0].option_description; viewModel.option_2 = Listar2.options[1].option_description; viewModel.option_3 = Listar2.options[2].option_description; return(View(viewModel)); } catch (Exception) { return(View()); } }
public VO_Enquete ListPollById(int id) { try { var strQuery = string.Format("SELECT E.ID, E.NM_DESCRICAO, E.NU_VIEW" + " FROM T_ENQUETE E " + " WHERE ID={0}", id); var strQueryO = string.Format("SELECT E.ID_OPCAO, E.NM_OPCAO_DESCRICAO, E.NU_VOTO " + " FROM T_OPCAO E " + " WHERE ID_ENQUETE={0} ORDER BY E.ID_OPCAO", id); StringBuilder strQueryView = new StringBuilder(); strQueryView.Append("UPDATE T_ENQUETE SET NU_VIEW = NU_VIEW + 1 "); strQueryView.Append(" WHERE ID="); strQueryView.Append(id); Conexao DadosEnquete = new Conexao(); DadosEnquete.ExecutarComando(strQueryView); SqlDataReader retornoReader = DadosEnquete.RetornoReader(strQuery); VO_Enquete obj = null; if (retornoReader.Read()) { obj = new VO_Enquete { poll_id = int.Parse(retornoReader["ID"].ToString()), poll_description = retornoReader["NM_DESCRICAO"].ToString(), }; VO_Enquete_Opcao objO = null; List <VO_Enquete_Opcao> objOList = new List <VO_Enquete_Opcao> { }; SqlDataReader retornoReaderO = DadosEnquete.RetornoReader(strQueryO); while (retornoReaderO.Read()) { objO = new VO_Enquete_Opcao { option_id = int.Parse(retornoReaderO["ID_OPCAO"].ToString()), option_description = retornoReaderO["NM_OPCAO_DESCRICAO"].ToString(), }; objOList.Add(objO); } obj.options = objOList; } return(obj); } catch (Exception ex) { throw ex; } }