Skip to content

Commit 4e6f616

Browse files
Chris Martinezcommonsensesoftware
authored andcommitted
Update examples with model binding
1 parent c0b0ec7 commit 4e6f616

File tree

20 files changed

+34
-26
lines changed

20 files changed

+34
-26
lines changed

samples/aspnetcore/BasicSample/Controllers/HelloWorldController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ public class HelloWorldController : Controller
1515
{
1616
// GET api/v{version}/helloworld
1717
[HttpGet]
18-
public IActionResult Get() => Ok( new { Controller = GetType().Name, Version = HttpContext.GetRequestedApiVersion().ToString() } );
18+
public IActionResult Get( ApiVersion apiVersion ) => Ok( new { Controller = GetType().Name, Version = apiVersion.ToString() } );
1919

2020
// GET api/v{version}/helloworld/{id}
2121
[HttpGet( "{id:int}", Name = "GetMessageById" )]
22-
public IActionResult Get( int id ) => Ok( new { Controller = GetType().Name, Id = id, Version = HttpContext.GetRequestedApiVersion().ToString() } );
22+
public IActionResult Get( int id, ApiVersion apiVersion ) => Ok( new { Controller = GetType().Name, Id = id, Version = apiVersion.ToString() } );
2323

2424
// POST api/v{version}/helloworld
2525
[HttpPost]

samples/aspnetcore/BasicSample/Controllers/ValuesController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ public class ValuesController : Controller
1212
{
1313
// GET api/values?api-version=1.0
1414
[HttpGet]
15-
public string Get() => $"Controller = {GetType().Name}\nVersion = {HttpContext.GetRequestedApiVersion()}";
15+
public string Get( ApiVersion apiVersion ) => $"Controller = {GetType().Name}\nVersion = {apiVersion}";
1616
}
1717
}

samples/aspnetcore/ByNamespaceSample/V1/Controllers/AgreementsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public class AgreementsController : Controller
1010
// GET ~/v1/agreements/{accountId}
1111
// GET ~/agreements/{accountId}?api-version=1.0
1212
[HttpGet( "{accountId}" )]
13-
public IActionResult Get( string accountId ) => Ok( new Agreement( GetType().FullName, accountId, HttpContext.GetRequestedApiVersion().ToString() ) );
13+
public IActionResult Get( string accountId, ApiVersion apiVersion ) => Ok( new Agreement( GetType().FullName, accountId, apiVersion.ToString() ) );
1414
}
1515
}

samples/aspnetcore/ByNamespaceSample/V1/Controllers/OrdersController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public class OrdersController : Controller
1010
// GET ~/v1/orders/{accountId}
1111
// GET ~/orders/{accountId}?api-version=1.0
1212
[HttpGet( "{accountId}" )]
13-
public IActionResult Get( string accountId ) => Ok( new Order( GetType().FullName, accountId, HttpContext.GetRequestedApiVersion().ToString() ) );
13+
public IActionResult Get( string accountId, ApiVersion apiVersion ) => Ok( new Order( GetType().FullName, accountId, apiVersion.ToString() ) );
1414
}
1515
}

samples/aspnetcore/ByNamespaceSample/V2/Controllers/AgreementsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public class AgreementsController : Controller
1010
// GET ~/v2/agreements/{accountId}
1111
// GET ~/agreements/{accountId}?api-version=2.0
1212
[HttpGet( "{accountId}" )]
13-
public IActionResult Get( string accountId ) => Ok( new Agreement( GetType().FullName, accountId, HttpContext.GetRequestedApiVersion().ToString() ) );
13+
public IActionResult Get( string accountId, ApiVersion apiVersion ) => Ok( new Agreement( GetType().FullName, accountId, apiVersion.ToString() ) );
1414
}
1515
}

samples/aspnetcore/ByNamespaceSample/V2/Controllers/OrdersController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public class OrdersController : Controller
1010
// GET ~/v2/orders/{accountId}
1111
// GET ~/orders/{accountId}?api-version=2.0
1212
[HttpGet( "{accountId}" )]
13-
public IActionResult Get( string accountId ) => Ok( new Order( GetType().FullName, accountId, HttpContext.GetRequestedApiVersion().ToString() ) );
13+
public IActionResult Get( string accountId, ApiVersion apiVersion ) => Ok( new Order( GetType().FullName, accountId, apiVersion.ToString() ) );
1414
}
1515
}

samples/aspnetcore/ByNamespaceSample/V3/Controllers/AgreementsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public class AgreementsController : Controller
1010
// GET ~/v3/agreements/{accountId}
1111
// GET ~/agreements/{accountId}?api-version=3.0
1212
[HttpGet( "{accountId}" )]
13-
public IActionResult Get( string accountId ) => Ok( new Agreement( GetType().FullName, accountId, HttpContext.GetRequestedApiVersion().ToString() ) );
13+
public IActionResult Get( string accountId, ApiVersion apiVersion ) => Ok( new Agreement( GetType().FullName, accountId, apiVersion.ToString() ) );
1414
}
1515
}

samples/aspnetcore/ByNamespaceSample/V3/Controllers/OrdersController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public class OrdersController : Controller
1010
// GET ~/v3/orders/{accountId}
1111
// GET ~/orders/{accountId}?api-version=3.0
1212
[HttpGet( "{accountId}" )]
13-
public IActionResult Get( string accountId ) => Ok( new Order( GetType().FullName, accountId, HttpContext.GetRequestedApiVersion().ToString() ) );
13+
public IActionResult Get( string accountId, ApiVersion apiVersion ) => Ok( new Order( GetType().FullName, accountId, apiVersion.ToString() ) );
1414
}
1515
}

samples/aspnetcore/ConventionsSample/Controllers/HelloWorldController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ public class HelloWorldController : Controller
1111
{
1212
// GET api/v{version}/helloworld
1313
[HttpGet]
14-
public string Get() => $"Controller = {GetType().Name}\nVersion = {HttpContext.GetRequestedApiVersion()}";
14+
public string Get( ApiVersion apiVersion ) => $"Controller = {GetType().Name}\nVersion = {apiVersion}";
1515

1616
// GET api/v{version}/helloworld/{id}
1717
[HttpGet( "{id:int}" )]
18-
public string Get( int id ) => $"Controller = {GetType().Name}\nId = {id}\nVersion = {HttpContext.GetRequestedApiVersion()}";
18+
public string Get( int id, ApiVersion apiVersion ) => $"Controller = {GetType().Name}\nId = {id}\nVersion = {apiVersion}";
1919
}
2020
}

samples/aspnetcore/ConventionsSample/Controllers/ValuesController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ public class ValuesController : Controller
1111
{
1212
// GET api/values?api-version=1.0
1313
[HttpGet]
14-
public string Get() => $"Controller = {GetType().Name}\nVersion = {HttpContext.GetRequestedApiVersion()}";
14+
public string Get( ApiVersion apiVersion ) => $"Controller = {GetType().Name}\nVersion = {apiVersion}";
1515

1616
// GET api/values/{id}?api-version=1.0
1717
[HttpGet( "{id:int}" )]
18-
public string Get( int id ) => $"Controller = {GetType().Name}\nId = {id}\nVersion = {HttpContext.GetRequestedApiVersion()}";
18+
public string Get( int id, ApiVersion apiVersion ) => $"Controller = {GetType().Name}\nId = {id}\nVersion = {apiVersion}";
1919
}
2020
}

0 commit comments

Comments
 (0)