protected override async Task OnInitializedAsync()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
comments = await dbContext.Comments.ToListAsync();
totalComments = comments.Count;
var user = authState.User;
if (user.Identity.IsAuthenticated)
{
loggedInUserGuid = user.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value;
}
appUser = await dbContext.Users.FindAsync(loggedInUserGuid);
lastSeenComments = appUser.LastSeenComments;
var groupedComments = comments.GroupBy(c => c.CreatedAt <= lastSeenComments)
.ToDictionary(g => g.Key, g => g.ToList());
oldComments = groupedComments.GetValueOrDefault(true, new List<Comment>());
newComments = groupedComments.GetValueOrDefault(false, new List<Comment>());
appUser.LastSeenComments = DateTime.UtcNow;
dbContext.Users.Update(appUser);
await dbContext.SaveChangesAsync();
}
protected override async Task OnInitializedAsync()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
comments = await dbContext.Comments.ToListAsync();
totalComments = comments.Count;
var user = authState.User;
if (user.Identity.IsAuthenticated)
{
loggedInUserGuid = user.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value;
}
appUser = await dbContext.Users.FindAsync(loggedInUserGuid);
lastSeenComments = appUser.LastSeenComments;
var groupedComments = comments.GroupBy(c => c.CreatedAt <= lastSeenComments)
.ToDictionary(g => g.Key, g => g.ToList());
oldComments = groupedComments.GetValueOrDefault(true, new List<Comment>());
newComments = groupedComments.GetValueOrDefault(false, new List<Comment>());
appUser.LastSeenComments = DateTime.UtcNow;
dbContext.Users.Update(appUser);
await dbContext.SaveChangesAsync();
}