diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/DashboardService.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/DashboardService.cs index bd98ac5b..95dd2355 100644 --- a/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/DashboardService.cs +++ b/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/DashboardService.cs @@ -8,17 +8,15 @@ using AutoMapper; using LearningHub.Nhs.Models.Dashboard; using LearningHub.Nhs.Models.Enums; + using LearningHub.Nhs.Models.Moodle; using LearningHub.Nhs.Models.Moodle.API; using LearningHub.Nhs.Models.MyLearning; + using LearningHub.Nhs.Models.Provider; using LearningHub.Nhs.OpenApi.Repositories.Interface.Repositories; using LearningHub.Nhs.OpenApi.Repositories.Interface.Repositories.Activity; - using LearningHub.Nhs.Models.Provider; using LearningHub.Nhs.OpenApi.Repositories.Interface.Repositories.Hierarchy; using LearningHub.Nhs.OpenApi.Repositories.Interface.Repositories.Resources; - using LearningHub.Nhs.OpenApi.Repositories.Repositories.Activity; using LearningHub.Nhs.OpenApi.Services.Interface.Services; - using LearningHub.Nhs.Models.Entities.Resource; - using System.Diagnostics; /// /// The DashboardService. @@ -277,7 +275,8 @@ public async Task GetMyInprogressLearning if (entrolledCourses != null) { - mappedEnrolledCourses = entrolledCourses?.Results? + var courses = entrolledCourses?.Results ?? Enumerable.Empty(); + mappedEnrolledCourses = courses .Where(r => r.Data?.Courses != null) .SelectMany(r => r.Data.Courses) .Select(course => new MyLearningCombinedActivitiesViewModel @@ -357,7 +356,7 @@ public async Task GetUserCertificateDet } // Await all active tasks in parallel - if (courseCertificatesTask != null & dashboardTrayLearningResourceType == "all") + if (courseCertificatesTask != null && dashboardTrayLearningResourceType == "all") await Task.WhenAll(courseCertificatesTask, resourceCertificatesTask); else if (dashboardTrayLearningResourceType == "elearning") await resourceCertificatesTask; @@ -390,7 +389,7 @@ public async Task GetUserCertificateDet CertificateDownloadUrl = c.DownloadLink, ResourceVersionId = 0, ProvidersJson = null - }); + }) ?? Enumerable.Empty(); } var allCertificates = resourceCertificates.Concat(mappedCourseCertificates); diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/MyLearningService.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/MyLearningService.cs index 7ff1bba1..8d179365 100644 --- a/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/MyLearningService.cs +++ b/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/MyLearningService.cs @@ -250,7 +250,7 @@ public async Task GetUserRecentMyLearning CertificateAwardedDate = course.EndDate.HasValue ? DateTimeOffset.FromUnixTimeSeconds(course.EndDate.Value) : DateTimeOffset.MinValue, - }).ToList(); + }).ToList()?? new List(); ; } // Combine both result sets @@ -397,7 +397,7 @@ public async Task GetUserLearningHistoryA CertificateAwardedDate = course.EndDate.HasValue ? DateTimeOffset.FromUnixTimeSeconds(course.EndDate.Value) : DateTimeOffset.MinValue, - }).ToList(); + }).ToList()?? new List(); } } @@ -763,7 +763,7 @@ public async Task GetUserCertificateDet CertificateDownloadUrl = c.DownloadLink, ResourceVersionId = 0, ProvidersJson = null, - }); + }) ?? Enumerable.Empty(); } var allCertificates = resourceCertificates.Concat(mappedCourseCertificates);