qol: user device assignment helper methods for expressions
This commit is contained in:
@@ -55,21 +55,6 @@ namespace Disco.Models.Repository
|
|||||||
[InverseProperty(nameof(DeviceComment.Device))]
|
[InverseProperty(nameof(DeviceComment.Device))]
|
||||||
public virtual IList<DeviceComment> DeviceComments { get; set; }
|
public virtual IList<DeviceComment> DeviceComments { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A list of the current device assignments, ordered by the most recent assignment date.
|
|
||||||
/// </summary>
|
|
||||||
[NotMapped]
|
|
||||||
public IList<DeviceUserAssignment> CurrentDeviceUserAssignments
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return DeviceUserAssignments?
|
|
||||||
.Where(dua => dua.UnassignedDate is null)
|
|
||||||
.OrderByDescending(dua => dua.AssignedDate)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
if (DeviceModel != null)
|
if (DeviceModel != null)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Disco.Models.Repository
|
namespace Disco.Models.Repository
|
||||||
{
|
{
|
||||||
@@ -66,6 +67,36 @@ namespace Disco.Models.Repository
|
|||||||
[NotMapped]
|
[NotMapped]
|
||||||
public AttachmentTypes HasAttachmentType { get { return AttachmentTypes.User; } }
|
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()
|
public override string ToString()
|
||||||
=> $"{DisplayName} ({UserId})";
|
=> $"{DisplayName} ({UserId})";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user