#10333 Template Updates

This commit is contained in:
Isaac Levin 2019-05-20 10:55:15 -04:00
parent 5502c2080e
commit 19bf518de1
4 changed files with 89 additions and 94 deletions

View File

@ -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<IEnumerable<string>> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
[HttpGet("{id}")]
public ActionResult<string> 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
}
}
}

View File

@ -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<WeatherResult> GetWeatherResult(string location)
{
var rng = new Random();
return new WeatherResult
{
Location = location,
Temperature = rng.Next(-20, 55),
TemperatureUnit = TemperatureUnit.Celsius
};
}
[HttpGet]
public ActionResult<WeatherResult> 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; }
}
}

View File

@ -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
[<Route("api/[controller]")>]
[<ApiController>]
type ValuesController () =
inherit ControllerBase()
[<HttpGet>]
member this.Get() =
let values = [|"value1"; "value2"|]
ActionResult<string[]>(values)
[<HttpGet("{id}")>]
member this.Get(id:int) =
let value = "value"
ActionResult<string>(value)
[<HttpPost>]
member this.Post([<FromBody>] value:string) =
()
[<HttpPut("{id}")>]
member this.Put(id:int, [<FromBody>] value:string ) =
()
[<HttpDelete("{id}")>]
member this.Delete(id:int) =
()

View File

@ -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
[<Route("api/SampleData/[controller]")>]
[<ApiController>]
type WeatherController () =
inherit ControllerBase()
[<HttpGet>]
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<WeatherResult>(result)
[<HttpGet>]
member this.Get(location:string) =
let rnd = System.Random()
let result = new WeatherResult (Location = location, Temperature = rnd.Next(-20, 55), TemperatureUnit = TemperatureUnit.Celsius)
ActionResult<WeatherResult>(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