Issues with datetimes and MongoDB
I am storing creation time and "completion" time of an order. The creation time displays the day off by one, but that's not my issue.
C# sets complete time to 1/1/0001 12:00:00 AM because it is just a new datetime with no actual date. When an order is complete it should update the time with the current time but nothing happens.
I have debugged the code endlessly, I am near certain it is not a small programming error but some weird interaction between Bson objects and datetime. As you will see in this method I change the status and the completion time. The status will change however the completion time will not. How can I get this datetime property to update? Any help will be much appreciated.
public class OrderModel { Irrelevant properties... [BsonElement("Status")] public string Status { get; set; } [BsonElement("CreateTime")] public DateTime CreateTime { get; set; } [BsonElement("CompleteTime")] public DateTime CompleteTime { get; set; } } public async Task<IActionResult> Complete([FromQuery] string orderId) { var order = await pizzaRepository.GetOrder(orderId); order.CompleteTime = DateTime.Now; order.Status = "Complete"; await pizzaRepository.UpdateOrder(order); return Redirect("Status"); }
0 comments:
Post a Comment