Skip to content

Commit

Permalink
Show Username on Log Page (#1735)
Browse files Browse the repository at this point in the history
* do manual left join for autohistory user ids to get user names

* fix formatting
  • Loading branch information
Masterjun3 authored Jan 14, 2024
1 parent c078af8 commit a0a3cc4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion TASVideos/Pages/Logs/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<tr>
<td>@entry.RowId</td>
<td>@entry.UserId</td>
<td>@entry.UserName</td>
<td>
<timezone-convert asp-for="@entry.Created"/>
</td>
Expand Down
17 changes: 9 additions & 8 deletions TASVideos/Pages/Logs/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ public IndexModel(ApplicationDbContext db)
public async Task<IActionResult> OnGet()
{
var query = _db.AutoHistory
.Select(h => new LogEntry
.GroupJoin(_db.Users, outerKey => outerKey.UserId, innerKey => innerKey.Id, (h, user) => new { h, user })
.SelectMany(g => g.user.DefaultIfEmpty(), (g, user) => new LogEntry
{
RowId = h.RowId,
UserId = h.UserId,
Created = h.Created,
TableName = h.TableName,
Changed = h.Changed,
Kind = h.Kind,
RowId = g.h.RowId,
UserName = user == null ? "Unknown_User" : user.UserName,
Created = g.h.Created,
TableName = g.h.TableName,
Changed = g.h.Changed,
Kind = g.h.Kind,
});

if (!string.IsNullOrWhiteSpace(Table))
Expand Down Expand Up @@ -70,7 +71,7 @@ public class LogEntry
public string RowId { get; init; } = "";

[Sortable]
public int UserId { get; init; }
public string UserName { get; init; }

[Sortable]
public DateTime Created { get; init; } = DateTime.UtcNow;
Expand Down

0 comments on commit a0a3cc4

Please sign in to comment.