-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controller1.cs
79 lines (72 loc) · 2.19 KB
/
Controller1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Threading.Tasks;
using api.model;
using Microsoft.AspNetCore.Mvc;
namespace api
{
[Route("/")]
public class Controller1 : Controller
{
// GET
[HttpGet]
public IActionResult Get()
{
return Ok("Hello from 1");
}
[Route("date-time-query")]
[HttpGet]
public IActionResult GetDateTimeQuery([FromQuery] DateTime arg)
{
/*
For built-in JSON serialization AND NewtonsoftJson AND NewtonsoftJson with DateTimeZoneHandling.UTC:
10:00-5 >> 07:00-8
10:00Z >> 02:00-8
*/
return Ok(arg.ToString("O"));
}
[Route("date-time-offset-query")]
[HttpGet]
public IActionResult GetDateTimeOffsetQuery([FromQuery] DateTimeOffset arg)
{
/*
For NewtonsoftJson with DateTimeZoneHandling.UTC:
10:00-5 >> 10:00-5
10:00Z >> 10:00+0
*/
return Ok(arg.ToString("O"));
}
[Route("date-time-body")]
[HttpGet]
public IActionResult GetDateTimeBody([FromBody] DateTime arg)
{
/*
For built-in JSON serialization AND NewtonsoftJson:
10:00-5 >> 07:00-8
10:00Z >> 10:00Z
For NewtonsoftJson with DateTimeZoneHandling.UTC:
10:00-5 >> 15:00Z
10:00Z >> 10:00Z
*/
return Ok(arg.ToString("O"));
}
[Route("model-body")]
[HttpGet]
public IActionResult GetDateTimeBody([FromBody] Model1 model1)
{
/*
For NewtonsoftJson with DateTimeZoneHandling.UTC:
*/
return Ok(model1.DateTimeField.ToString("O"));
}
[HttpPost("validating-endpoint")]
public IActionResult ValidatingEndpoint([FromBody] ModelWithAnnotations model)
{
if (!ModelState.IsValid)
{
// hmm... can't seem to reach here with proper validation. See ModelWithAnnotations
return BadRequest(ModelState);
}
return Ok(model);
}
}
}