Remove lastloggings use loggings

This commit is contained in:
Martijn Scheepers
2026-01-22 10:33:34 +01:00
parent 4f9e01939e
commit 52adeef1f1
4 changed files with 24 additions and 27 deletions

View File

@@ -27,16 +27,16 @@ namespace Aperio_Control_Centre.ACSDatabase.Models.Extensions
}
}
public static Task<List<Logging>> LastUserLoggings(this DbSet<Logging> loggings, User user, int count, CancellationToken token)
{
return loggings
.Where(l => l.UserId == user.Id)
.OrderByDescending(t => t.Time)
.Take(count)
.Include(d => d.Device)
.Include(d => d.Device.Location)
.ToListAsync(token);
}
//public static Task<List<Logging>> LastUserLoggings(this DbSet<Logging> loggings, User user, int count, CancellationToken token)
//{
// return loggings
// .Where(l => l.UserId == user.Id)
// .OrderByDescending(t => t.Time)
// .Take(count)
// .Include(d => d.Device)
// .Include(d => d.Device.Location)
// .ToListAsync(token);
//}
public static Task<List<Logging>> LastDeviceLoggings(this DbSet<Logging> loggings, Device device, int count, CancellationToken token)
{

View File

@@ -92,9 +92,6 @@ namespace Aperio_Control_Centre.ACSDatabase.Models
//--------------------------------------------------------------
[NotMapped]
public List<Logging> LastLoggings { get; } = [];
[NotMapped]
public SelectList? DepartmentsSelectList { get; set; }

View File

@@ -220,7 +220,7 @@ namespace Aperio_Control_Centre.Controllers
.AsNoTracking()
.AsAsyncEnumerable())
{
Debug.WriteLine($"{user.Name} - {user.Loggings?.Count}");
//Debug.WriteLine($"{user.Name} - {user.Loggings?.Count}");
if (user.Loggings?.Count != 0)
{
if (user.Loggings?.FirstOrDefault()?.Time < timeout)
@@ -230,7 +230,7 @@ namespace Aperio_Control_Centre.Controllers
}
else
{
Debug.WriteLine($"---- {user.Name} - {user.Created} - {timeout}");
//Debug.WriteLine($"---- {user.Name} - {user.Created} - {timeout}");
if (user.Created < timeout)
{
userlist.Add(user);
@@ -379,6 +379,7 @@ namespace Aperio_Control_Centre.Controllers
using ACSDatabaseContext db = await _contextFactory.CreateDbContextAsync(token);
User? user = await db.Users
.Where(i => i.Id == id)
.Include(l => l.Loggings!.OrderByDescending(t => t.Time).Take(25)).ThenInclude(d=> d.Device).ThenInclude(d => d!.Location)
.SingleOrDefaultAsync(token);
if (user == null)
@@ -388,7 +389,6 @@ namespace Aperio_Control_Centre.Controllers
user.DepartmentsSelectList = await db.Departments.DepartmentsSelectList(token);
user.UserGroupsSelectList.AddRange(await db.UserGroups.UserGroupsListItems(user, token));
user.LastLoggings?.AddRange(await db.Loggings.LastUserLoggings(user, 25, token));
user.ExpiryDays = await db.GlobalSettings.CardExpiryDays(db, token);
this.CreateTitle();
@@ -511,6 +511,7 @@ namespace Aperio_Control_Centre.Controllers
User? user = await db.Users
.Where(i => i.Id == id)
.Include(d => d.Department)
.Include(l => l.Loggings!.Where(a => a.Access != null).OrderByDescending(t => t.Time).Take(25))
.SingleOrDefaultAsync(token);
if (user == null)
@@ -518,7 +519,6 @@ namespace Aperio_Control_Centre.Controllers
return NotFound();
}
user.UserGroupsSelectList.AddRange(await db.UserGroups.UserGroupsListItems(user, token));
user.LastLoggings.AddRange(await db.Loggings.LastUserLoggings(user, 25, token));
user.ExpiryDays = await db.GlobalSettings.CardExpiryDays(db, token);
this.CreateTitle();
@@ -573,6 +573,7 @@ namespace Aperio_Control_Centre.Controllers
User? user = await db.Users
.Where(i => i.Id == id)
.Include(d => d.Department)
.Include(l => l.Loggings!.Where(a => a.Access != null).OrderByDescending(t => t.Time).Take(25))
.SingleOrDefaultAsync(token);
if (user == null)
@@ -580,7 +581,6 @@ namespace Aperio_Control_Centre.Controllers
return NotFound();
}
user.UserGroupsSelectList.AddRange(await db.UserGroups.UserGroupsListItems(user, token));
user.LastLoggings.AddRange(await db.Loggings.LastUserLoggings(user, 25, token));
user.ExpiryDays = await db.GlobalSettings.CardExpiryDays(db, token);
this.CreateTitle();
@@ -639,6 +639,7 @@ namespace Aperio_Control_Centre.Controllers
User? user = await db.Users
.Where(i => i.Id == id)
.Include(d => d.Department)
.Include(l => l.Loggings!.Where(a => a.Access != null).OrderByDescending(t => t.Time).Take(25))
.SingleOrDefaultAsync(token);
if (user == null)
@@ -646,7 +647,6 @@ namespace Aperio_Control_Centre.Controllers
return NotFound();
}
user.UserGroupsSelectList.AddRange(await db.UserGroups.UserGroupsListItems(user, token));
user.LastLoggings.AddRange(await db.Loggings.LastUserLoggings(user, 25, token));
user.ExpiryDays = await db.GlobalSettings.CardExpiryDays(db, token);
this.CreateTitle();

View File

@@ -71,29 +71,29 @@
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(m => m.LastLoggings.First().Time)
@Html.DisplayNameFor(m => m.Loggings.First().Time)
</th>
<th>
@Html.DisplayNameFor(m => m.LastLoggings.First().Message)
@Html.DisplayNameFor(m => m.Loggings.First().Message)
</th>
<th>
@Html.DisplayNameFor(m => m.LastLoggings.First().Access)
@Html.DisplayNameFor(m => m.Loggings.First().Access)
</th>
<th>
@Html.DisplayNameFor(m => m.LastLoggings.First().Device!.Name)
@Html.DisplayNameFor(m => m.Loggings.First().Device!.Name)
</th>
<th>
@Html.DisplayNameFor(m => m.LastLoggings.First().Device!.Location!.ShortAddressString)
@Html.DisplayNameFor(m => m.Loggings.First().Device!.Location!.ShortAddressString)
</th>
<th>
@Html.DisplayNameFor(m => m.LastLoggings.First().UserName)
@Html.DisplayNameFor(m => m.Loggings.First().UserName)
</th>
<th>
@Html.DisplayNameFor(m => m.LastLoggings.First().LogType)
@Html.DisplayNameFor(m => m.Loggings.First().LogType)
</th>
</tr>
@foreach (var item in Model.LastLoggings)
@foreach (var item in Model.Loggings)
{
<tr>
<td>