diff --git a/Disco.Models/Services/Jobs/JobLists/JobLocationReference.cs b/Disco.Models/Services/Jobs/JobLists/JobLocationReference.cs index acf63a5b..1ec1de0d 100644 --- a/Disco.Models/Services/Jobs/JobLists/JobLocationReference.cs +++ b/Disco.Models/Services/Jobs/JobLists/JobLocationReference.cs @@ -9,6 +9,6 @@ namespace Disco.Models.Services.Jobs.JobLists public class JobLocationReference { public string Location { get; set; } - public List References { get; set; } + public List References { get; set; } } } diff --git a/Disco.Services/Jobs/JobLists/JobTableExtensions.cs b/Disco.Services/Jobs/JobLists/JobTableExtensions.cs index 73cf0152..9625cd6e 100644 --- a/Disco.Services/Jobs/JobLists/JobTableExtensions.cs +++ b/Disco.Services/Jobs/JobLists/JobTableExtensions.cs @@ -259,9 +259,9 @@ namespace Disco.Services return queueItems.Where(qi => usersQueues.ContainsKey(qi.QueueId)); } - public static IEnumerable JobLocationReferences(this IEnumerable Items, IEnumerable IncludeLocations) + public static IEnumerable JobLocationReferences(this IEnumerable Items, IEnumerable IncludeLocations) { - var innerItems = Items.Where(i => !string.IsNullOrWhiteSpace(i.DeviceHeldLocation)); + var innerItems = Items.Where(i => !string.IsNullOrWhiteSpace(i.DeviceHeldLocation) && i.DeviceHeld.HasValue && !i.DeviceReturnedDate.HasValue); return IncludeLocations.GroupJoin(innerItems, o => o, i => i.DeviceHeldLocation, (i, o) => new JobLocationReference @@ -271,9 +271,9 @@ namespace Disco.Services }, StringComparer.InvariantCultureIgnoreCase); } - public static IEnumerable JobLocationReferences(this IEnumerable Items) + public static IEnumerable JobLocationReferences(this IEnumerable Items) { - return Items.Where(i => !string.IsNullOrWhiteSpace(i.DeviceHeldLocation)) + return Items.Where(i => !string.IsNullOrWhiteSpace(i.DeviceHeldLocation) && i.DeviceHeld.HasValue && !i.DeviceReturnedDate.HasValue) .GroupBy(i => i.DeviceHeldLocation, StringComparer.InvariantCultureIgnoreCase) .Select(i => new JobLocationReference() { diff --git a/Disco.Web/Areas/API/Controllers/JobController.cs b/Disco.Web/Areas/API/Controllers/JobController.cs index ad570e13..0cf0d06e 100644 --- a/Disco.Web/Areas/API/Controllers/JobController.cs +++ b/Disco.Web/Areas/API/Controllers/JobController.cs @@ -2158,13 +2158,13 @@ namespace Disco.Web.Areas.API.Controllers throw new InvalidOperationException("Unknown Location Mode Configured"); } - var locationReferences = ManagedJobList.OpenJobsTable(j => j).Items.JobLocationReferences(locations); + var locationReferences = ManagedJobList.OpenJobsTable(j => j).Items.Cast().JobLocationReferences(locations); var results = locationReferences.Select(locRef => { string reference = null; - if (locRef.References == null && locRef.References.Count > 0) + if (locRef.References != null && locRef.References.Count > 0) { if (locRef.References.Count == 1) reference = string.Format("Job {0}", locRef.References[0].JobId); diff --git a/Disco.Web/Controllers/JobController.cs b/Disco.Web/Controllers/JobController.cs index 339a7650..d2eee92a 100644 --- a/Disco.Web/Controllers/JobController.cs +++ b/Disco.Web/Controllers/JobController.cs @@ -354,7 +354,7 @@ namespace Disco.Web.Controllers { m.LocationMode = Database.DiscoConfiguration.JobPreferences.LocationMode; if (m.LocationMode == LocationModes.RestrictedList) - m.LocationOptions = ManagedJobList.OpenJobsTable(j => j).Items.JobLocationReferences(Database.DiscoConfiguration.JobPreferences.LocationList).ToList(); + m.LocationOptions = ManagedJobList.OpenJobsTable(j => j).Items.Cast().JobLocationReferences(Database.DiscoConfiguration.JobPreferences.LocationList).ToList(); } // UI Extensions