From: Krzysztof Wieclaw Date: Tue, 6 Nov 2018 12:34:47 +0000 (+0100) Subject: Added posting forms to test-racing controller X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f80d58b09d517c4afdd5fa7d849f71753ac69b22;p=service%2Fcloud%2Fgear-racing-cloud.git Added posting forms to test-racing controller --- diff --git a/GearRacingCloud/Controllers/TestController.cs b/GearRacingCloud/Controllers/TestController.cs index b894614..fbc46bc 100644 --- a/GearRacingCloud/Controllers/TestController.cs +++ b/GearRacingCloud/Controllers/TestController.cs @@ -48,30 +48,34 @@ namespace GearRacingCloud.Controllers } [HttpPost] - public async Task Car() + public async Task PostCar() { string uri = "https://"+Request.Host.ToUriComponent()+"/api/racing"; var content = _CreateJsonContent(HttpContext.Request.Form["post"]); var res = await client.PostAsync(uri, content); - TempData["PostResult"] = res.ToString(); + TempData["PostResult"] = res.StatusCode.ToString(); return RedirectToAction("RacingCars"); } - [HttpGet] - public async Task Car(object o) + [HttpPost] + public async Task GetCar() { string uri = "https://" + Request.Host.ToUriComponent() + "/api/racing"; string mac; if (HttpContext.Request.Form.ContainsKey("get")) + { mac = HttpContext.Request.Form["get"]; + uri += "?apMac=" + mac; + } else + { mac = null; - uri += "?apMac=" + mac; + } var res = await client.GetAsync(uri); if (mac == null) - TempData["AllResult"] = res.ToString(); + TempData["AllResult"] = await res.Content.ReadAsStringAsync(); else - TempData["MACResult"] = res.ToString(); + TempData["MACResult"] = await res.Content.ReadAsStringAsync(); return RedirectToAction("RacingCars"); } } diff --git a/GearRacingCloud/Views/Test/RacingCars.cshtml b/GearRacingCloud/Views/Test/RacingCars.cshtml index 5184025..6bff748 100644 --- a/GearRacingCloud/Views/Test/RacingCars.cshtml +++ b/GearRacingCloud/Views/Test/RacingCars.cshtml @@ -10,7 +10,7 @@
POST /api/racing
- @using (Html.BeginForm("car", "test", FormMethod.Post)) + @using (Html.BeginForm("PostCar", "test", FormMethod.Post)) { @Html.TextArea("post", configuration.GetValue("Defaults:Texts:PostCar"), new { style = "width: 100%; max-width: 100%;", rows = 8 }); @@ -22,9 +22,9 @@
-
POST /api/racing
+
GET /api/racing?apMac=
- @using (Html.BeginForm("car", "test", FormMethod.Get)) + @using (Html.BeginForm("GetCar", "test", FormMethod.Post)) { @Html.TextArea("get", configuration.GetValue("Defaults:Texts:CarMAC"), new { style = "width: 100%; max-width: 100%;", rows = 8 }); @@ -36,9 +36,9 @@
-
POST /api/racing
+
GET/api/racing
- @using (Html.BeginForm("car", "test", FormMethod.Get)) + @using (Html.BeginForm("GetCar", "test", FormMethod.Post)) { }