/// <summary> /// issue a web request to add a stock tip for the current username. /// Only submit the request if a stock is selected /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void AddStockButton_Click(object sender, EventArgs e) { MultipartFormDataContent form = new MultipartFormDataContent(); statusLabel.Text = $"adding stock tip to {DGV_Filter.CurrentRow.Cells[0].Value}"; //if selected row is not null run request, //grab the first column value and sent it to post data for a request if (DGV_Filter.SelectedRows != null) { //Anonymously set postdata request //must have user enter a username(needed to run request) //and a stock symbol must be picked to get add tip data var postData = new[] { new{ k = "username", v = UsernameTextBox.Text }, new{ k = "action", v = "addtip" }, new{ k = "symbol", v = DGV_Filter.CurrentRow.Cells[0].Value.ToString() },//=DGV_currently_selected_stock_symbol new{ k = "tip", v = addTipTextBox.Text } }; // Transfer postdata to be sent foreach (var item in postData) { form.Add(new StringContent(item.v), item.k); } } else { statusLabel.Text = "error must select a stock"; } //send POSTdata request to webservice, return and add new tip to symbol and database using (HttpClient hc = new HttpClient()) { //send post request var postResponse = await hc.PostAsync(url, form); //if there is content in request, //read it as a string and call a decode method to Deserialized json data if (postResponse.Content != null) { //seriealize content response as a string asynchronously var stringResp = await postResponse.Content.ReadAsStringAsync(); //decode method to Deserialized json data and display to DGV_Tips AddTipDecode(stringResp);//is this needded for add stocks DGV_Tips.AutoResizeColumns(); } } }
/// <summary> /// issue a web request for all available stock tips classified as newest ( obvious ). /// For ALL stock tips, returns a bunch of the most recent additions ( newest first ) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void NewTipButton_Click(object sender, EventArgs e) { MultipartFormDataContent form = new MultipartFormDataContent(); statusLabel.Text = "getting newest stock tips"; //Anonymously set postdata request //must have user enter a username(needed to run request) var postData = new[] { new{ k = "username", v = UsernameTextBox.Text }, new{ k = "action", v = "tips" }, new{ k = "flag", v = "newest" } }; // Transfer postdata to be sent foreach (var item in postData) { form.Add(new StringContent(item.v), item.k); } //send POSTdata request to webservice, return and display data in DGV_filter using (HttpClient hc = new HttpClient()) { //send post request var postResponse = await hc.PostAsync(url, form); //if there is content in request, //read it as a string and call a decode method to Deserialized json data if (postResponse.Content != null) { //seriealize content response as a string asynchronously var stringResp = await postResponse.Content.ReadAsStringAsync(); //decode method to Deserialized json data and display to DGV_Tips TipDecode(stringResp); DGV_Tips.AutoResizeColumns(); } } }