From 5f4f49f91ef035e017d7b6b250800098e17cbe30 Mon Sep 17 00:00:00 2001 From: Swapnamol Abraham Date: Mon, 15 Jul 2024 14:52:26 +0100 Subject: [PATCH] TD-4362: Session LMS error --- .../Controllers/Api/ScormController.cs | 8 ++-- .../Resources/IResourceVersionRepository.cs | 14 ++++++ .../Resources/ResourceVersionRepository.cs | 43 +++++++++++++++++++ .../ActivityService.cs | 2 +- 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ScormController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ScormController.cs index ba9ed57f3..6a8f7d699 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ScormController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ScormController.cs @@ -335,10 +335,10 @@ private async Task GetSco(int resourceReferenceId) // 1. StudentDataMasteryScore, StudentDataMaxTimeAllowed, StudentDataTimeLimitAction, Credit sco.Credit = "credit"; sco.CommentsFromLms = ScormContansts.CommentsFromLMS; - sco.LaunchData = rv.ScormDetails.ScormManifest.LaunchData ?? ScormContansts.LaunchData; - sco.StudentDataMasteryScore = rv.ScormDetails.ScormManifest.MasteryScore ?? ScormContansts.StudentDataMasteryScore; - sco.StudentDataMaxTimeAllowed = rv.ScormDetails.ScormManifest.MaxTimeAllowed ?? ScormContansts.StudentDataMaxTimeAllowed; - sco.StudentDataTimeLimitAction = rv.ScormDetails.ScormManifest.TimeLimitAction ?? ScormContansts.StudentDataTimeLimitAction; + sco.LaunchData = rv?.ScormDetails?.ScormManifest?.LaunchData ?? ScormContansts.LaunchData; + sco.StudentDataMasteryScore = rv?.ScormDetails?.ScormManifest?.MasteryScore ?? ScormContansts.StudentDataMasteryScore; + sco.StudentDataMaxTimeAllowed = rv?.ScormDetails?.ScormManifest?.MaxTimeAllowed ?? ScormContansts.StudentDataMaxTimeAllowed; + sco.StudentDataTimeLimitAction = rv?.ScormDetails?.ScormManifest?.TimeLimitAction ?? ScormContansts.StudentDataTimeLimitAction; // 2. LessonLocation, ScoreRaw, SuspendData, Entry // If previous Scorm Activity was "incomplete" then offer pick-up from previous lesson location. diff --git a/WebAPI/LearningHub.Nhs.Repository.Interface/Resources/IResourceVersionRepository.cs b/WebAPI/LearningHub.Nhs.Repository.Interface/Resources/IResourceVersionRepository.cs index 00cbff4d7..2a96c845e 100644 --- a/WebAPI/LearningHub.Nhs.Repository.Interface/Resources/IResourceVersionRepository.cs +++ b/WebAPI/LearningHub.Nhs.Repository.Interface/Resources/IResourceVersionRepository.cs @@ -59,6 +59,13 @@ public interface IResourceVersionRepository : IGenericRepositoryThe . Task GetCurrentForResourceAsync(int resourceId); + /// + /// The get current resource for resourceid async. + /// + /// The resource Id. + /// The . + Task GetCurrentResourceDetailsAsync(int resourceId); + /// /// The get current published for resource async. /// @@ -73,6 +80,13 @@ public interface IResourceVersionRepository : IGenericRepositoryThe . Task GetCurrentForResourceReferenceIdAsync(int resourceReferenceId); + /// + /// The get current resource for resource reference id async. + /// + /// The resource reference id. + /// The . + Task GetCurrentResourceForResourceReferenceIdAsync(int resourceReferenceId); + /// /// The get current published for resource reference id async. /// diff --git a/WebAPI/LearningHub.Nhs.Repository/Resources/ResourceVersionRepository.cs b/WebAPI/LearningHub.Nhs.Repository/Resources/ResourceVersionRepository.cs index 10bf4cddf..477a4c416 100644 --- a/WebAPI/LearningHub.Nhs.Repository/Resources/ResourceVersionRepository.cs +++ b/WebAPI/LearningHub.Nhs.Repository/Resources/ResourceVersionRepository.cs @@ -160,6 +160,30 @@ public async Task GetCurrentForResourceAsync(int resourceId) && !r.Deleted); } + /// + /// The get current for resource async. + /// + /// The resource id. + /// The . + public async Task GetCurrentResourceDetailsAsync(int resourceId) + { + return await this.DbContext.ResourceVersion.AsNoTracking() + .Include(r => r.Resource) + .Include(r => r.Publication).AsNoTracking() + .Include(r => r.ResourceVersionKeyword).AsNoTracking() + .Include(r => r.ResourceVersionAuthor).AsNoTracking() + .Include(r => r.ResourceVersionFlag).AsNoTracking() + .Include(r => r.ResourceVersionEvent).AsNoTracking() + .Include(r => r.ResourceLicence).AsNoTracking() + .Include(r => r.CreateUser).AsNoTracking() + .Include(r => r.ResourceVersionProvider).ThenInclude(r => r.Provider).AsNoTracking() + .OrderByDescending(r => r.Id) + .FirstOrDefaultAsync(r => r.ResourceId == resourceId + && r.VersionStatusEnum != VersionStatusEnum.FailedToPublish + && r.VersionStatusEnum != VersionStatusEnum.Draft + && !r.Deleted); + } + /// /// The get current published for resource async. /// @@ -233,6 +257,25 @@ public async Task GetCurrentForResourceReferenceIdAsync(int res return retVal; } + /// + /// The get current for resource reference id async. + /// + /// The resource reference id. + /// The . + public async Task GetCurrentResourceForResourceReferenceIdAsync(int resourceReferenceId) + { + ResourceVersion retVal = null; + + var or = this.DbContext.ResourceReference.OrderByDescending(r => r.Id).FirstOrDefault(x => x.OriginalResourceReferenceId == resourceReferenceId); + + if (or != null) + { + retVal = await this.GetCurrentResourceDetailsAsync(or.ResourceId); + } + + return retVal; + } + /// /// The get current published for resource reference id async. /// diff --git a/WebAPI/LearningHub.Nhs.Services/ActivityService.cs b/WebAPI/LearningHub.Nhs.Services/ActivityService.cs index e8e9972b3..19c98e376 100644 --- a/WebAPI/LearningHub.Nhs.Services/ActivityService.cs +++ b/WebAPI/LearningHub.Nhs.Services/ActivityService.cs @@ -438,7 +438,7 @@ public async Task LaunchScormActivity(int currentUserId, var scormActivitySummary = this.scormActivityRepository.GetScormActivitySummary(currentUserId, launchScormActivityViewModel.ResourceReferenceId); var scormActivityId = this.scormActivityRepository.Create(currentUserId, launchScormActivityViewModel.ResourceReferenceId); - var resourceVersion = await this.resourceVersionRepository.GetCurrentForResourceReferenceIdAsync(launchScormActivityViewModel.ResourceReferenceId); + var resourceVersion = await this.resourceVersionRepository.GetCurrentResourceForResourceReferenceIdAsync(launchScormActivityViewModel.ResourceReferenceId); var activeContent = new ActiveContentViewModel() { ScormActivityId = scormActivityId,