|
18 | 18 | using LearningHub.Nhs.Repository.Interface.Resources; |
19 | 19 | using LearningHub.Nhs.Services.Helpers; |
20 | 20 | using LearningHub.Nhs.Services.Interface; |
| 21 | + using Microsoft.Data.SqlClient; |
21 | 22 | using Microsoft.EntityFrameworkCore; |
22 | 23 | using Microsoft.Extensions.Logging; |
23 | 24 | using Microsoft.Rest; |
@@ -526,6 +527,39 @@ public async Task<LearningHubValidationResult> CompleteScormActivity(int current |
526 | 527 | return new LearningHubValidationResult(true); |
527 | 528 | } |
528 | 529 |
|
| 530 | + /// <summary> |
| 531 | + /// Complete scorm activity. |
| 532 | + /// </summary> |
| 533 | + /// <param name="currentUserId">The user Id.</param> |
| 534 | + /// <param name="completeScormActivityViewModel">The update scorm Activity View Model.</param> |
| 535 | + /// <returns>The <see cref="Task"/>.</returns> |
| 536 | + public async Task<LearningHubValidationResult> ScormCompleteActivity(int currentUserId, ScormActivityViewModel completeScormActivityViewModel) |
| 537 | + { |
| 538 | + try |
| 539 | + { |
| 540 | + if (completeScormActivityViewModel.LessonStatusId.HasValue |
| 541 | + && (completeScormActivityViewModel.LessonStatusId.Value == (int)ActivityStatusEnum.Completed |
| 542 | + || completeScormActivityViewModel.LessonStatusId == (int)ActivityStatusEnum.Passed |
| 543 | + || completeScormActivityViewModel.LessonStatusId == (int)ActivityStatusEnum.Failed)) |
| 544 | + { |
| 545 | + // Handle activity "complete" event - create new ResourceActivity record & perform any re-calc status updates. |
| 546 | + this.scormActivityRepository.Complete(currentUserId, completeScormActivityViewModel.InstanceId); |
| 547 | + } |
| 548 | + } |
| 549 | + catch (SqlException ex) |
| 550 | + { |
| 551 | + if (!ex.Message.Contains( |
| 552 | + "ResourceActivity entry with Completed status already exists", |
| 553 | + StringComparison.OrdinalIgnoreCase)) |
| 554 | + { |
| 555 | + throw; |
| 556 | + } |
| 557 | + // else: intentionally ignore |
| 558 | + } |
| 559 | + |
| 560 | + return new LearningHubValidationResult(true); |
| 561 | + } |
| 562 | + |
529 | 563 | /// <summary> |
530 | 564 | /// The resolve scorm activity. |
531 | 565 | /// Resolves any completed active content that does not have associated completion events. |
|
0 commit comments