qol: user device assignment helper methods for expressions

This commit is contained in:
Gary Sharp
2025-08-13 16:15:53 +10:00
parent 53fdea5325
commit 676ff82e4b
2 changed files with 31 additions and 15 deletions
+31
View File
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
namespace Disco.Models.Repository
{
@@ -66,6 +67,36 @@ namespace Disco.Models.Repository
[NotMapped]
public AttachmentTypes HasAttachmentType { get { return AttachmentTypes.User; } }
/// <summary>
/// A list of the current device assignments, ordered by the most recent assignment date.
/// </summary>
[NotMapped]
public IList<DeviceUserAssignment> CurrentDeviceAssignments
{
get
{
return DeviceUserAssignments?
.Where(dua => dua.UnassignedDate == null)
.OrderByDescending(dua => dua.AssignedDate)
.ToList() ?? new List<DeviceUserAssignment>();
}
}
/// <summary>
/// The most recent, current device assignment. Null if there are no current assignments.
/// </summary>
[NotMapped]
public DeviceUserAssignment LatestCurrentDeviceAssignment
{
get
{
return DeviceUserAssignments
.Where(dua => dua.UnassignedDate == null)
.OrderByDescending(dua => dua.AssignedDate)
.FirstOrDefault();
}
}
public override string ToString()
=> $"{DisplayName} ({UserId})";