When I make a JSON call from AngularJS to my WebApi controller via a GET request, my dates come through to my model as 'Local' kind. This is fine and how I want it to work.
However, when I change the method to POST (on both the WebApi controller and my AngularJS client side code), the dates are an hour out because the DateTime kind is now UTC. The dates are serialized via .toJSON() before being sent and everything looks the same via Chrome's network inspection when looking at the GET and POST requests.
How can I keep the DateTime Kind's consistent across POST and GET requests so that they are always Local?
Edit #1:
Angular JS Call:
var params = {
DateFrom: detail.from.toJSON(),
DateTo: detail.to.toJSON(),
Filters: detail.filters
};
return http.post(window.urls.apiGetAllErrorsGraphData, params);
In my current example, the value of params.DateFrom = "2014-04-30T23:00:00.000Z", detail.from = 01/05/2014 as a JS Date object.
'http.post' in this case is an Angular service that I wrote that basically wraps HTTP calls.
.NET WebAPI Controller
[POST("api/errors/chart")]
[HttpPost]
[HttpOptions]
public IHttpActionResult GetAllErrorsGraphData([FromBody]AllErrorChartDetails details)
{
var results = chartDataService.GenerateAllErrorsData(details.DateFrom, details.DateTo, details.Filters);
return Ok(results.Select(x => new { date = x.Key, errors = x.Value }));
}
I'm using AttributeRouting if you're curious what the attributes are over the method.