Clean up TryParse samples
parent
c05b6c0bb7
commit
f7ce7c88cb
|
@ -20,6 +20,8 @@ namespace BindTryParseAPI.Controllers
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// <snippet2>
|
||||||
|
// GET /WeatherForecast?culture=en-GB
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult Get([FromQuery] Culture? culture)
|
public IActionResult Get([FromQuery] Culture? culture)
|
||||||
{
|
{
|
||||||
|
@ -40,7 +42,10 @@ namespace BindTryParseAPI.Controllers
|
||||||
|
|
||||||
return Ok(weatherForecasts);
|
return Ok(weatherForecasts);
|
||||||
}
|
}
|
||||||
|
// </snippet2>
|
||||||
|
|
||||||
|
// <snippet>
|
||||||
|
// GET /WeatherForecast/GetByRange?range=07/12/2022-07/14/2022
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("GetByRange")]
|
[Route("GetByRange")]
|
||||||
public IActionResult Range([FromQuery] DateRange? range)
|
public IActionResult Range([FromQuery] DateRange? range)
|
||||||
|
@ -63,5 +68,6 @@ namespace BindTryParseAPI.Controllers
|
||||||
|
|
||||||
return Ok(weatherForecasts);
|
return Ok(weatherForecasts);
|
||||||
}
|
}
|
||||||
|
// </snippet>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
namespace BindTryParseAPI.Models
|
namespace BindTryParseAPI.Models
|
||||||
{
|
{
|
||||||
|
// <snippet>
|
||||||
public class Culture
|
public class Culture
|
||||||
{
|
{
|
||||||
public string? DisplayName { get; }
|
public string? DisplayName { get; }
|
||||||
|
@ -24,4 +25,5 @@ namespace BindTryParseAPI.Models
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// </snippet>
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
namespace BindTryParseAPI.Models
|
namespace BindTryParseAPI.Models
|
||||||
{
|
{
|
||||||
|
// <snippet>
|
||||||
public class DateRange
|
public class DateRange
|
||||||
{
|
{
|
||||||
public DateOnly? From { get; }
|
public DateOnly? From { get; }
|
||||||
|
@ -29,4 +30,5 @@ namespace BindTryParseAPI.Models
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// </snippet>
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,8 @@ namespace BindTryParseMVC.Controllers
|
||||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
// <snippet>
|
||||||
/// /WeatherForecast?culture=en-GB
|
//GET /WeatherForecast?culture=en-GB
|
||||||
/// </summary>
|
|
||||||
/// <param name="culture"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public IActionResult Index(Culture? culture)
|
public IActionResult Index(Culture? culture)
|
||||||
{
|
{
|
||||||
var weatherForecasts = Enumerable
|
var weatherForecasts = Enumerable
|
||||||
|
@ -35,12 +32,10 @@ namespace BindTryParseMVC.Controllers
|
||||||
|
|
||||||
return View(weatherForecasts);
|
return View(weatherForecasts);
|
||||||
}
|
}
|
||||||
|
// </snippet>
|
||||||
|
|
||||||
/// <summary>
|
// GET /WeatherForecast/Range?range=07/12/2022-07/14/2022
|
||||||
/// /WeatherForecast/Range?range=07/12/2022-07/14/2022
|
// <snippet_1>
|
||||||
/// </summary>
|
|
||||||
/// <param name="range"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public IActionResult Range(DateRange? range)
|
public IActionResult Range(DateRange? range)
|
||||||
{
|
{
|
||||||
var weatherForecasts = Enumerable
|
var weatherForecasts = Enumerable
|
||||||
|
@ -50,7 +45,8 @@ namespace BindTryParseMVC.Controllers
|
||||||
TemperatureC = Random.Shared.Next(-20, 55),
|
TemperatureC = Random.Shared.Next(-20, 55),
|
||||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||||
})
|
})
|
||||||
.Where(wf => DateOnly.FromDateTime(wf.Date) >= (range?.From ?? DateOnly.MinValue) && DateOnly.FromDateTime(wf.Date) <= (range?.To ?? DateOnly.MaxValue))
|
.Where(wf => DateOnly.FromDateTime(wf.Date) >= (range?.From ?? DateOnly.MinValue)
|
||||||
|
&& DateOnly.FromDateTime(wf.Date) <= (range?.To ?? DateOnly.MaxValue))
|
||||||
.Select(wf => new WeatherForecastViewModel
|
.Select(wf => new WeatherForecastViewModel
|
||||||
{
|
{
|
||||||
Date = wf.Date.ToString(CultureInfo.InvariantCulture),
|
Date = wf.Date.ToString(CultureInfo.InvariantCulture),
|
||||||
|
@ -61,5 +57,6 @@ namespace BindTryParseMVC.Controllers
|
||||||
|
|
||||||
return View("Index", weatherForecasts);
|
return View("Index", weatherForecasts);
|
||||||
}
|
}
|
||||||
|
// </snippet_1>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
namespace BindTryParseMVC.Models
|
namespace BindTryParseMVC.Models
|
||||||
{
|
{
|
||||||
|
// <snippet>
|
||||||
public class Culture
|
public class Culture
|
||||||
{
|
{
|
||||||
public string? DisplayName { get; }
|
public string? DisplayName { get; }
|
||||||
|
@ -24,4 +25,5 @@ namespace BindTryParseMVC.Models
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// </snippet>
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
namespace BindTryParseMVC.Models
|
namespace BindTryParseMVC.Models
|
||||||
{
|
{
|
||||||
|
// <snippet>
|
||||||
public class DateRange
|
public class DateRange
|
||||||
{
|
{
|
||||||
public DateOnly? From { get; }
|
public DateOnly? From { get; }
|
||||||
|
@ -29,4 +30,5 @@ namespace BindTryParseMVC.Models
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// </snippet>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue