From f1965eb316915ac79b85b73d59c8d5909b4c3f3e Mon Sep 17 00:00:00 2001 From: Adam O'Neil Date: Sun, 21 Apr 2024 06:51:08 -0400 Subject: [PATCH] added time zone to profile manage page --- .../Account/Pages/Manage/Index.razor | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ApiAuthDemo/ApiAuthDemo/Components/Account/Pages/Manage/Index.razor b/ApiAuthDemo/ApiAuthDemo/Components/Account/Pages/Manage/Index.razor index a946f2b..fb03662 100644 --- a/ApiAuthDemo/ApiAuthDemo/Components/Account/Pages/Manage/Index.razor +++ b/ApiAuthDemo/ApiAuthDemo/Components/Account/Pages/Manage/Index.razor @@ -3,11 +3,13 @@ @using System.ComponentModel.DataAnnotations @using Microsoft.AspNetCore.Identity @using ApiAuthDemo.Data +@using Microsoft.EntityFrameworkCore; @inject UserManager UserManager @inject SignInManager SignInManager @inject IdentityUserAccessor UserAccessor @inject IdentityRedirectManager RedirectManager +@inject ApplicationDbContext DbContext Profile @@ -28,6 +30,16 @@ +
+ + + @foreach (var item in allTimeZones) + { + + } + + +
@@ -37,6 +49,8 @@ private ApplicationUser user = default!; private string? username; private string? phoneNumber; + private string? timeZoneId; + private IEnumerable allTimeZones = []; [CascadingParameter] private HttpContext HttpContext { get; set; } = default!; @@ -46,11 +60,15 @@ protected override async Task OnInitializedAsync() { + allTimeZones = TimeZoneInfo.GetSystemTimeZones().OrderBy(val => val.StandardName); + user = await UserAccessor.GetRequiredUserAsync(HttpContext); username = await UserManager.GetUserNameAsync(user); phoneNumber = await UserManager.GetPhoneNumberAsync(user); + timeZoneId = user.TimeZoneId; Input.PhoneNumber ??= phoneNumber; + Input.TimeZoneId ??= timeZoneId; } private async Task OnValidSubmitAsync() @@ -64,6 +82,13 @@ } } + if (Input.TimeZoneId != timeZoneId) + { + await DbContext.Users + .Where(row => row.UserName == user.UserName) + .ExecuteUpdateAsync(setter => setter.SetProperty(row => row.TimeZoneId, Input.TimeZoneId)); + } + await SignInManager.RefreshSignInAsync(user); RedirectManager.RedirectToCurrentPageWithStatus("Your profile has been updated", HttpContext); } @@ -73,5 +98,8 @@ [Phone] [Display(Name = "Phone number")] public string? PhoneNumber { get; set; } + + [Display(Name = "Time Zone")] + public string? TimeZoneId { get; set; } } }