diff --git a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Drivers/UserTimeZoneDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Drivers/UserTimeZoneDisplayDriver.cs index c89d5d592dd..c1295275809 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Drivers/UserTimeZoneDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Drivers/UserTimeZoneDisplayDriver.cs @@ -43,9 +43,6 @@ UpdateEditorContext context await context.Updater.TryUpdateModelAsync(model, Prefix); userTimeZone.TimeZoneId = model.TimeZoneId; - // Remove the cache entry, don't update it, as the form might still fail validation for other reasons. - await _userTimeZoneService.UpdateUserTimeZoneAsync(user); - return await EditAsync(userTimeZone, context); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/TimeZoneUserEventHandler.cs b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/TimeZoneUserEventHandler.cs new file mode 100644 index 00000000000..81d44bf8040 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Handlers/TimeZoneUserEventHandler.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.DependencyInjection; +using OrchardCore.Users.Handlers; +using OrchardCore.Users.TimeZone.Services; + +namespace OrchardCore.Users.TimeZone.Handlers; +public class TimeZoneUserEventHandler : UserEventHandlerBase +{ + private readonly UserTimeZoneService _userTimeZoneService; + + public TimeZoneUserEventHandler(UserTimeZoneService userTimeZoneService) => _userTimeZoneService = userTimeZoneService; + + public override async Task DeletedAsync(UserDeleteContext context) => await _userTimeZoneService.UpdateUserTimeZoneAsync(context.User); + + public override async Task UpdatedAsync(UserUpdateContext context) => await _userTimeZoneService.UpdateUserTimeZoneAsync(context.User); +} diff --git a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Startup.cs index 4f518d3700d..925a4a0fc24 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/TimeZone/Startup.cs @@ -1,8 +1,10 @@ using Microsoft.Extensions.DependencyInjection; using OrchardCore.DisplayManagement.Handlers; using OrchardCore.Modules; +using OrchardCore.Users.Handlers; using OrchardCore.Users.Models; using OrchardCore.Users.TimeZone.Drivers; +using OrchardCore.Users.TimeZone.Handlers; using OrchardCore.Users.TimeZone.Services; namespace OrchardCore.Users.TimeZone @@ -15,6 +17,7 @@ public override void ConfigureServices(IServiceCollection services) services.AddScoped(); services.AddSingleton(); services.AddScoped, UserTimeZoneDisplayDriver>(); + services.AddScoped(); } } }