fix Convert FormData แล้วเขียนลง Logs
This commit is contained in:
parent
e4dccb5c1f
commit
0fb3fd1d06
2 changed files with 63 additions and 2 deletions
25
BMA.EHR.Domain/Middlewares/DateTimeFixConverter.cs
Normal file
25
BMA.EHR.Domain/Middlewares/DateTimeFixConverter.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace BMA.EHR.Domain.Middlewares
|
||||
{
|
||||
public class DateTimeFixConverter : JsonConverter<DateTime>
|
||||
{
|
||||
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.String)
|
||||
{
|
||||
if (DateTime.TryParse(reader.GetString(), out var date))
|
||||
{
|
||||
return date;
|
||||
}
|
||||
}
|
||||
throw new JsonException("Invalid date format.");
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value.ToString("yyyy-MM-dd"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue