Exemplo n.º 1
0
        private void Submit_Click(object sender, EventArgs e)
        {
            string selection = CandidatesListBox.SelectedItem.ToString();
            Regex  pattern   = new Regex(@"(\d)\s-\s(?:.+)");
            Match  match     = pattern.Match(selection);
            string number    = match.Groups[1].Value.Trim();

            var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://fanatichacktues.herokuapp.com/voters");

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                string json = "{\"voter\":{\"egn\":\"" + egn + "\",\"vote\":\"" + number + "\"}}";

                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
            }
            Successfully succ = new Successfully();

            succ.Show();
            this.WindowState = FormWindowState.Minimized;
            ShowInTaskbar    = false;
        }
Exemplo n.º 2
0
        private void Submit_Click(object sender, EventArgs e)
        {
            string selection = CandidatesListBox.SelectedItem.ToString();
            Regex pattern = new Regex(@"(\d)\s-\s(?:.+)");
            Match match = pattern.Match(selection);
            string number = match.Groups[1].Value.Trim();

            var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://fanatichacktues.herokuapp.com/voters");
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                string json = "{\"voter\":{\"egn\":\"" + egn + "\",\"vote\":\"" + number + "\"}}";

                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
            }
            Successfully succ = new Successfully();
            succ.Show();
            this.WindowState = FormWindowState.Minimized;
            ShowInTaskbar = false;
        }