Pedro
Pedro
CC#
Created by AceChewy on 8/30/2023 in #help
❔ Creating a server for a messaging app
😍 😍 😍 😍 😍
22 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
ok then
42 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
yeah
42 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
hmm
42 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
just dont know if they will look at it and find strange or bad practices
42 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
haha
42 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
it does
42 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
is this ok?
42 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
.
42 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
so, i came with that solution
42 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
yeah
42 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
otherwise i would keep it
42 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
its just the specification for this internship project i got
42 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
and i added to the program.cs
builder.Services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.Converters.Add(new DateTimeConverter());
});
builder.Services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.Converters.Add(new DateTimeConverter());
});
42 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
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 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"));
}
}
}
42 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
i created a class DateTimeConverter
42 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
but i dont know if it is a good practice
42 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
so i came with this idea
42 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
for some reason it still doesnt work
42 replies
CC#
Created by Pedro on 8/28/2023 in #help
❔ problem with DateTime format
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>();

}
}
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>();

}
}
42 replies