Base solution for your next web application

Activities of "gekko"

Hi, I have an application build with AspnetCore + JQuery.

I want to hide a menu item if a tenant has a certain feature activated. In other words, I want to show one menu item if the feature is activated, but show another menu item if the feature is not activated.

In AppNavigationProvicer.cs I can add Menuitems with "featureDependency". If the feature is activated, the menu item is shown, otherwise not. But I want also the opposite. Is that possible?

Question

Solution: Angular + Asp.Net Core Version: 13.1.1

Issue: After upgrading from version 12.2.1 to Version 13.1.1 submitting a datetime value as UTC does not work correctly.

After you upgraded to .Net 8 , you also removed .AddNewtonsoftJson() from Startup.cs

What I do is submitting data that contains a date value explicit as UTC, here an example of Json data we want to submit:

{
    "id": 3133,
    "name": "Test mission",
	...
    "date": "2024-05-10T00:00:00.000Z",
	...
}

As you can see, the "date" value is formatted as UTC.

The c# Type of "date" is DateTime:

public DateTime Date { get; set; }

When submitting the data to the api, the date kind is now not Utc but local. I tested this:

without .AddNewtonsoftJson() in Startup.cs

var test = input.Date.Kind; // => local

but with .AddNewtonsoftJson() in Startup.cs

var test = input.Date.Kind; // => Utc

I did a simple additional test in the same CreateOrUpdate method (without .AddNewtonsoftJson() in Startup.cs)

var testDate = System.Text.Json.JsonSerializer.Deserialize<DateTime>("\"2024-05-14T00:00:00.000Z\"");
var testKind = testDate.Kind; // => Utc

From this simple test I can see that System.Text.Json can understand that this is intended as Utc date, but why is it not with the date I am sending to the api?

The problem with the new setting is, that the data saved to the database does change the time part of the date. In my case it has a value of +2 hours : 2024-05-14 02:00:00.0000000

All suggestions about this I found was to implement a custom JsonConverter for Datetime. I tried to implement one, but unfortunately it does never hit:

Converter:

using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace custom.JsonConverters
{
    public class JsonDateTimeConverter : JsonConverter<DateTime>
    {
        public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            return DateTime.Parse(reader.GetString()).ToUniversalTime();
        }

        public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
        {
            writer.WriteStringValue(value.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ"));
        }
    }
}

In Startup.cs :

mvcBuilder.AddJsonOptions(options =>
{
	options.JsonSerializerOptions.Converters.Add(new JsonDateTimeConverter());
});

Do you have an idea what is wrong?

Showing 1 to 2 of 2 entries