//********************Estatística********************\\ // GET: Poll/5/Stats public async System.Threading.Tasks.Task <ActionResult> Stats(int id) { Baseurl = Baseurl + id + "/Stats"; VO_Parcial obj = null; try { 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; votoUi.BaseAddress = new Uri(Baseurl); var resposta = await votoUi.GetAsync(""); string dados = await resposta.Content.ReadAsStringAsync(); obj = JsonConvert.DeserializeObject <VO_Parcial>(dados.ToString()); } VO_View objReturn = new VO_View(); objReturn.qty_1 = obj.votes[0].qty; objReturn.qty_2 = obj.votes[1].qty; objReturn.qty_3 = obj.votes[2].qty; objReturn.views = obj.views; return(View(objReturn)); } catch (Exception ex) { throw ex; } }
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()); } }
//********************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 async System.Threading.Tasks.Task <ActionResult> Cadastrar(VO_View viewModel) { try { viewModel.id = 0; //// TODO: Add insert logic here var handler = new WebRequestHandler(); handler.ServerCertificateValidationCallback = delegate { return(true); }; using (HttpClient enqueteUi = new HttpClient(handler)) { enqueteUi.BaseAddress = new Uri(Baseurl); ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; var resposta = await enqueteUi.GetAsync(""); VO_Enquete_Post enquete_post = new VO_Enquete_Post(); enquete_post.poll_description = viewModel.description; enquete_post.options = new string[3]; enquete_post.options[0] = viewModel.option_1; enquete_post.options[1] = viewModel.option_2; enquete_post.options[2] = viewModel.option_3; var serializedEnquete = JsonConvert.SerializeObject(enquete_post); var content = new StringContent(serializedEnquete, Encoding.UTF8, "application/json"); var result = await enqueteUi.PostAsync(Baseurl, content); } return(RedirectToAction("Index")); } catch { return(View()); } }
public async System.Threading.Tasks.Task <ActionResult> Editar(VO_View viewModel) { Baseurl = Baseurl + viewModel.id; TB_Enquete enquete = new TB_Enquete(); enquete.poll_id = viewModel.id; enquete.poll_description = Request["description"]; enquete.options = new List <TB_Opcao> { new TB_Opcao { poll_id = viewModel.id, option_description = Request["option_1"], option_id = 1 }, new TB_Opcao { poll_id = viewModel.id, option_description = Request["option_2"], option_id = 2 }, new TB_Opcao { poll_id = viewModel.id, option_description = Request["option_3"], option_id = 3 } }; 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(""); var serializedEnquete = JsonConvert.SerializeObject(enquete); var content = new StringContent(serializedEnquete, Encoding.UTF8, "application/json"); var result = await votoUi.PutAsync(Baseurl, content); } return(RedirectToAction("Index")); } catch { return(View()); } }
//********************Cadastro********************\\ // GET: Poll public async System.Threading.Tasks.Task <ActionResult> Cadastrar() { var model = new VO_View(); var handler = new WebRequestHandler(); handler.ServerCertificateValidationCallback = delegate { return(true); }; using (HttpClient tipovotoUi = new HttpClient(handler)) { tipovotoUi.BaseAddress = new Uri(Baseurl); ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; var resposta = await tipovotoUi.GetAsync(""); } return(View(model)); }