Skip to content

Commit

Permalink
sample fix (dotnet#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rick-Anderson authored Jul 15, 2022
1 parent fe95a3b commit 2ec11d0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public IActionResult Get([FromQuery] Culture? culture)
// </snippet2>

// <snippet>
// GET /WeatherForecast/GetByRange?range=07/12/2022-07/14/2022
// GET /WeatherForecast/GetByRange?range=07/19/2022-07/14/2024
[HttpGet]
[Route("GetByRange")]
public IActionResult Range([FromQuery] DateRange? range)
Expand Down
3 changes: 1 addition & 2 deletions mvc/models/BindTryParseAPI/Models/DateRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public DateRange(string from, string to)
To = DateOnly.Parse(to);
}

public static bool TryParse(string? value, IFormatProvider? provider,
out DateRange? result)
public static bool TryParse(string? value, out DateRange? result)
{
if (string.IsNullOrEmpty(value) || value.Split('-').Length != 2)
{
Expand Down
6 changes: 5 additions & 1 deletion mvc/models/BindTryParseAPI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();

var app = builder.Build();
var uri = "/WeatherForecast/GetByRange?range=" +
$"{DateTime.Now.Date.ToShortDateString()}-" +
$"{DateTime.Now.AddDays(5).Date.ToShortDateString()}";

app.MapGet("/", () => Results.Redirect(uri));

app.UseAuthorization();

Expand Down

0 comments on commit 2ec11d0

Please sign in to comment.