From 19bf518de102a17b02f8ce6384691812ab5fac27 Mon Sep 17 00:00:00 2001 From: Isaac Levin Date: Mon, 20 May 2019 10:55:15 -0400 Subject: [PATCH] #10333 Template Updates --- .../Controllers/ValuesController.cs | 60 ------------------- .../Controllers/WeatherController.cs | 56 +++++++++++++++++ .../Controllers/ValuesController.fs | 34 ----------- .../Controllers/WeatherController.fs | 33 ++++++++++ 4 files changed, 89 insertions(+), 94 deletions(-) delete mode 100644 src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/ValuesController.cs create mode 100644 src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/WeatherController.cs delete mode 100644 src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/ValuesController.fs create mode 100644 src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/WeatherController.fs diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/ValuesController.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/ValuesController.cs deleted file mode 100644 index 55a45bf67f..0000000000 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/ValuesController.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -#if (!NoAuth) -using Microsoft.AspNetCore.Authorization; -#endif -using Microsoft.AspNetCore.Mvc; - -namespace Company.WebApplication1.Controllers -{ -#if (!NoAuth) - [Authorize] -#endif - [Route("api/[controller]")] - [ApiController] - public class ValuesController : ControllerBase - { - // GET api/values - [HttpGet] - public ActionResult> Get() - { - return new string[] { "value1", "value2" }; - } - - // GET api/values/5 - [HttpGet("{id}")] - public ActionResult Get(int id) - { - return "value"; - } - - // POST api/values - [HttpPost] - public void Post([FromBody] string value) - { -#if (OrganizationalAuth || WindowsAuth) - // For more information on protecting this API from Cross Site Request Forgery (CSRF) attacks, see https://go.microsoft.com/fwlink/?LinkID=717803 -#endif - } - - // PUT api/values/5 - [HttpPut("{id}")] - public void Put(int id, [FromBody] string value) - { -#if (OrganizationalAuth || WindowsAuth) - // For more information on protecting this API from Cross Site Request Forgery (CSRF) attacks, see https://go.microsoft.com/fwlink/?LinkID=717803 -#endif - } - - // DELETE api/values/5 - [HttpDelete("{id}")] - public void Delete(int id) - { -#if (OrganizationalAuth || WindowsAuth) - // For more information on protecting this API from Cross Site Request Forgery (CSRF) attacks, see https://go.microsoft.com/fwlink/?LinkID=717803 -#endif - } - } -} diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/WeatherController.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/WeatherController.cs new file mode 100644 index 0000000000..19f0cf9500 --- /dev/null +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/WeatherController.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +#if (!NoAuth) +using Microsoft.AspNetCore.Authorization; +#endif +using Microsoft.AspNetCore.Mvc; + +namespace Company.WebApplication1.Controllers +{ +#if (!NoAuth) + [Authorize] +#endif + + [Route("api/SampleData/[controller]")] + [ApiController] + public class WeatherController : ControllerBase + { + [HttpGet] + public ActionResult GetWeatherResult(string location) + { + var rng = new Random(); + return new WeatherResult + { + Location = location, + Temperature = rng.Next(-20, 55), + TemperatureUnit = TemperatureUnit.Celsius + }; + } + + [HttpGet] + public ActionResult GetWeatherForecasts(string location, TemperatureUnit unit) + { + var rng = new Random(); + return new WeatherResult + { + Location = location, + Temperature = rng.Next(-20, 55), + TemperatureUnit = unit + }; + } + } + + public enum TemperatureUnit + { + Celsius, + Fahrenheit + } + public class WeatherResult + { + public int Temperature { get; set; } + public TemperatureUnit Temperature { get; set; } + public string Location { get; set; } + } +} diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/ValuesController.fs b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/ValuesController.fs deleted file mode 100644 index c77d5d4b79..0000000000 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/ValuesController.fs +++ /dev/null @@ -1,34 +0,0 @@ -namespace Company.WebApplication1.Controllers - -open System -open System.Collections.Generic -open System.Linq -open System.Threading.Tasks -open Microsoft.AspNetCore.Mvc - -[] -[] -type ValuesController () = - inherit ControllerBase() - - [] - member this.Get() = - let values = [|"value1"; "value2"|] - ActionResult(values) - - [] - member this.Get(id:int) = - let value = "value" - ActionResult(value) - - [] - member this.Post([] value:string) = - () - - [] - member this.Put(id:int, [] value:string ) = - () - - [] - member this.Delete(id:int) = - () diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/WeatherController.fs b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/WeatherController.fs new file mode 100644 index 0000000000..b9aed30a0f --- /dev/null +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/WeatherController.fs @@ -0,0 +1,33 @@ +namespace Company.WebApplication1.Controllers + +open System +open System.Collections.Generic +open System.Linq +open System.Threading.Tasks +open Microsoft.AspNetCore.Mvc + +[] +[] +type WeatherController () = + inherit ControllerBase() + + [] + member this.Get(location:string, unit:TemperatureUnit) = + let rnd = System.Random() + let result = new WeatherResult (Location = location, Temperature = rnd.Next(-20, 55), TemperatureUnit = unit) + ActionResult(result) + + [] + member this.Get(location:string) = + let rnd = System.Random() + let result = new WeatherResult (Location = location, Temperature = rnd.Next(-20, 55), TemperatureUnit = TemperatureUnit.Celsius) + ActionResult(result) + +type TemperatureUnit = + | Celsius + | Fahrenheit + +type WeatherResult = + member val Temperature "" with get, set + member val TemperatureUnit "" with get, set + member val Location "" with get, set