Is this still the recommended way?
I find it a hassle to get something so trivial working. I completely agree to Ian. The grid should use UTC in all data transmission and localtime in the UI (maybe configurable similar as the kendo.culture setting.
I had to add this Data method to all datasource (Create and Update) methods for all pages. Some of them allready had a data method that makes it even more complex and less maintainable.
The Create, Update and Delete methods look similar to the one below. Conversion from db to view is done within the viewmodel, but because a validation error may occur i have to do this conversion within each CUD method too for every field for every controller. Again it is hard to maintain and easy to introduce bugs. Don't think Telerik can fix the viewmodel => viewmodel part i describe below. Any suggestions on that?
public ActionResult Booking_Update([DataSourceRequest]DataSourceRequest request, VMBooking viewmodel)
{
if (viewmodel != null && ModelState.IsValid)
{
var entity = (Booking)viewmodel;
db.Booking.Attach(entity);
db.Entry(entity).State = EntityState.Modified;
try
{
db.SaveChanges();
}
catch (Exception ex)
{
ModelState.AddModelError("updateerror", ex.GetOriginalException().Message);
}
}
//all viewmodel date fields are set to unspecified (effectively localtime) while you know it is UTC
//if you would send them back to the UI untouched, it will add/substract the timezone offset each time
viewmodel.StartTime = DateTime.SpecifyKind(viewmodel.StartTime, DateTimeKind.Utc);
viewmodel.EndTime = DateTime.SpecifyKind(viewmodel.EndTime, DateTimeKind.Utc);
viewmodel.EntryDate = DateTime.SpecifyKind(viewmodel.EntryDate, DateTimeKind.Utc);
viewmodel.FirstStateChange = DateTime.SpecifyKind(viewmodel.FirstStateChange, DateTimeKind.Utc);
return Json(new[] { viewmodel }.ToDataSourceResult(request, ModelState));
}