builder.Services.AddControllers().AddJsonOptions(options =>{ options.JsonSerializerOptions.Converters.Add(new DateTimeConverter());});
using System;using System.Text.Json;using System.Text.Json.Serialization;namespace EventEnroll.Utils{ public class DateTimeConverter : JsonConverter<DateTime> { public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { return DateTime.Parse(reader.GetString()); } public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) { writer.WriteStringValue(value.ToString("dd/MM/yyyy")); } }}
using EventEnroll.Models;using Microsoft.AspNetCore.Identity;using System.ComponentModel.DataAnnotations;using System.Text.Json.Serialization;namespace EventEnroll.Dtos.Event{ public class AddEventDto { public string Title { get; set; } = string.Empty; public string Description { get; set; } = string.Empty; [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")] public DateTime Date { get; set; } [JsonIgnore] public string? CreatorId { get; set; } [Required] public List<string> Attendees { get; set; } = new List<string>(); }}