diff --git a/Disco.Models/Repository/Device/Device.cs b/Disco.Models/Repository/Device/Device.cs index aee48001..5299c248 100644 --- a/Disco.Models/Repository/Device/Device.cs +++ b/Disco.Models/Repository/Device/Device.cs @@ -55,21 +55,6 @@ namespace Disco.Models.Repository [InverseProperty(nameof(DeviceComment.Device))] public virtual IList DeviceComments { get; set; } - /// - /// A list of the current device assignments, ordered by the most recent assignment date. - /// - [NotMapped] - public IList CurrentDeviceUserAssignments - { - get - { - return DeviceUserAssignments? - .Where(dua => dua.UnassignedDate is null) - .OrderByDescending(dua => dua.AssignedDate) - .ToList(); - } - } - public override string ToString() { if (DeviceModel != null) diff --git a/Disco.Models/Repository/User/User.cs b/Disco.Models/Repository/User/User.cs index 93868fe6..655a6d69 100644 --- a/Disco.Models/Repository/User/User.cs +++ b/Disco.Models/Repository/User/User.cs @@ -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; } } + /// + /// A list of the current device assignments, ordered by the most recent assignment date. + /// + [NotMapped] + public IList CurrentDeviceAssignments + { + get + { + return DeviceUserAssignments? + .Where(dua => dua.UnassignedDate == null) + .OrderByDescending(dua => dua.AssignedDate) + .ToList() ?? new List(); + } + } + + /// + /// The most recent, current device assignment. Null if there are no current assignments. + /// + [NotMapped] + public DeviceUserAssignment LatestCurrentDeviceAssignment + { + get + { + return DeviceUserAssignments + .Where(dua => dua.UnassignedDate == null) + .OrderByDescending(dua => dua.AssignedDate) + .FirstOrDefault(); + } + } + public override string ToString() => $"{DisplayName} ({UserId})";