11namespace LearningHub . Nhs . Repository . Resources
22{
3- using System . Collections . Generic ;
4- using System . Data ;
5- using System . Linq ;
6- using System . Threading . Tasks ;
7- using LearningHub . Nhs . Models . Entities . Resource ;
8- using LearningHub . Nhs . Models . Resource ;
9- using LearningHub . Nhs . Repository . Interface ;
10- using LearningHub . Nhs . Repository . Interface . Resources ;
11- using Microsoft . Data . SqlClient ;
12- using Microsoft . EntityFrameworkCore ;
3+ using System . Collections . Generic ;
4+ using System . Data ;
5+ using System . Linq ;
6+ using System . Threading . Tasks ;
7+ using LearningHub . Nhs . Models . Entities . Resource ;
8+ using LearningHub . Nhs . Models . Resource ;
9+ using LearningHub . Nhs . Repository . Interface ;
10+ using LearningHub . Nhs . Repository . Interface . Resources ;
11+ using Microsoft . Data . SqlClient ;
12+ using Microsoft . EntityFrameworkCore ;
1313
14+ /// <summary>
15+ /// The Scorm resource version repository.
16+ /// </summary>
17+ public class ScormResourceVersionRepository : GenericRepository < ScormResourceVersion > , IScormResourceVersionRepository
18+ {
1419 /// <summary>
15- /// The Scorm resource version repository .
20+ /// Initializes a new instance of the <see cref="ScormResourceVersionRepository"/> class .
1621 /// </summary>
17- public class ScormResourceVersionRepository : GenericRepository < ScormResourceVersion > , IScormResourceVersionRepository
22+ /// <param name="dbContext">The db context.</param>
23+ /// <param name="tzOffsetManager">The Timezone offset manager.</param>
24+ public ScormResourceVersionRepository ( LearningHubDbContext dbContext , ITimezoneOffsetManager tzOffsetManager )
25+ : base ( dbContext , tzOffsetManager )
1826 {
19- /// <summary>
20- /// Initializes a new instance of the <see cref="ScormResourceVersionRepository"/> class.
21- /// </summary>
22- /// <param name="dbContext">The db context.</param>
23- /// <param name="tzOffsetManager">The Timezone offset manager.</param>
24- public ScormResourceVersionRepository ( LearningHubDbContext dbContext , ITimezoneOffsetManager tzOffsetManager )
25- : base ( dbContext , tzOffsetManager )
26- {
27- }
27+ }
2828
29- /// <summary>
30- /// The get by id async.
31- /// </summary>
32- /// <param name="id">The id.</param>
33- /// <returns>The <see cref="Task"/>.</returns>
34- public async Task < ScormResourceVersion > GetByIdAsync ( int id )
35- {
36- return await this . DbContext . ScormResourceVersion . AsNoTracking ( ) . FirstOrDefaultAsync ( r => r . Id == id && ! r . Deleted ) ;
37- }
29+ /// <summary>
30+ /// The get by id async.
31+ /// </summary>
32+ /// <param name="id">The id.</param>
33+ /// <returns>The <see cref="Task"/>.</returns>
34+ public async Task < ScormResourceVersion > GetByIdAsync ( int id )
35+ {
36+ return await this . DbContext . ScormResourceVersion . AsNoTracking ( ) . FirstOrDefaultAsync ( r => r . Id == id && ! r . Deleted ) ;
37+ }
3838
39- /// <summary>
40- /// The get by resource version id async.
41- /// </summary>
42- /// <param name="resourceVersionId">The resource versionid.</param>
43- /// <param name="includeDeleted">Allows deleted items to be returned.</param>
44- /// <returns>The <see cref="Task"/>.</returns>
45- public async Task < ScormResourceVersion > GetByResourceVersionIdAsync ( int resourceVersionId , bool includeDeleted = false )
46- {
47- return await this . DbContext . ScormResourceVersion
48- . Include ( r => r . File )
49- . Include ( r => r . ScormResourceVersionManifest )
50- . AsNoTracking ( ) . FirstOrDefaultAsync ( r => r . ResourceVersionId == resourceVersionId && ( includeDeleted || ! r . Deleted ) ) ;
51- }
39+ /// <summary>
40+ /// The get by resource version id async.
41+ /// </summary>
42+ /// <param name="resourceVersionId">The resource versionid.</param>
43+ /// <param name="includeDeleted">Allows deleted items to be returned.</param>
44+ /// <returns>The <see cref="Task"/>.</returns>
45+ public async Task < ScormResourceVersion > GetByResourceVersionIdAsync ( int resourceVersionId , bool includeDeleted = false )
46+ {
47+ return await this . DbContext . ScormResourceVersion
48+ . Include ( r => r . File )
49+ . Include ( r => r . ScormResourceVersionManifest )
50+ . AsNoTracking ( ) . FirstOrDefaultAsync ( r => r . ResourceVersionId == resourceVersionId && ( includeDeleted || ! r . Deleted ) ) ;
51+ }
5252
53- /// <summary>
54- /// Gets the SCORM content details for a particular Learning Hub external reference (guid).
55- /// </summary>
56- /// <param name="externalReference">The external reference (guid).</param>
57- /// <returns>A ContentServerViewModel.</returns>
58- public async Task < ContentServerViewModel > GetContentServerDetailsByLHExternalReference ( string externalReference )
59- {
60- var param0 = new SqlParameter ( "@externalReference" , SqlDbType . NVarChar ) { Value = externalReference } ;
53+ /// <summary>
54+ /// Gets the SCORM content details for a particular Learning Hub external reference (guid).
55+ /// </summary>
56+ /// <param name="externalReference">The external reference (guid).</param>
57+ /// <returns>A ContentServerViewModel.</returns>
58+ public ContentServerViewModel GetContentServerDetailsByLHExternalReference ( string externalReference )
59+ {
60+ var param0 = new SqlParameter ( "@externalReference" , SqlDbType . NVarChar ) { Value = externalReference } ;
6161
62- var scormContentData = await this . DbContext . ContentServerViewModel . FromSqlRaw ( "[resources].[GetContentServerDetailsForLHExternalReference] @externalReference" , param0 ) . AsNoTracking ( ) . ToListAsync ( ) ;
62+ var scormContentServerViewModel = this . DbContext . ContentServerViewModel . FromSqlRaw ( "[resources].[GetContentServerDetailsForLHExternalReference] @externalReference" , param0 ) . AsEnumerable ( ) . FirstOrDefault ( ) ;
6363
64- ContentServerViewModel scormContentServerViewModel = scormContentData . AsEnumerable ( ) . FirstOrDefault ( ) ;
65- return scormContentServerViewModel ;
66- }
64+ return scormContentServerViewModel ;
65+ }
6766
68- /// <summary>
69- /// Gets the SCORM content details for a particular historic external URL. These historic URLs have to be supported to
70- /// allow historic ESR links on migrated resources to continue to work.
71- /// </summary>
72- /// <param name="externalUrl">The external Url.</param>
73- /// <returns>A ContentServerViewModel.</returns>
74- public async Task < ContentServerViewModel > GetScormContentServerDetailsByHistoricExternalUrl ( string externalUrl )
75- {
76- var param0 = new SqlParameter ( "@externalUrl" , SqlDbType . NVarChar ) { Value = externalUrl } ;
67+ /// <summary>
68+ /// Gets the SCORM content details for a particular historic external URL. These historic URLs have to be supported to
69+ /// allow historic ESR links on migrated resources to continue to work.
70+ /// </summary>
71+ /// <param name="externalUrl">The external Url.</param>
72+ /// <returns>A ContentServerViewModel.</returns>
73+ public ContentServerViewModel GetScormContentServerDetailsByHistoricExternalUrl ( string externalUrl )
74+ {
75+ var param0 = new SqlParameter ( "@externalUrl" , SqlDbType . NVarChar ) { Value = externalUrl } ;
76+
77+ var scormContentServerViewModel = this . DbContext . ContentServerViewModel . FromSqlRaw ( "[resources].[GetScormContentServerDetailsForHistoricExternalUrl] @externalUrl" , param0 ) . ToList ( ) . FirstOrDefault < ContentServerViewModel > ( ) ;
7778
78- var scormContentData = await this . DbContext . ContentServerViewModel . FromSqlRaw ( "[resources].[GetScormContentServerDetailsForHistoricExternalUrl] @externalUrl" , param0 ) . AsNoTracking ( ) . ToListAsync ( ) ;
79- ContentServerViewModel scormContentServerViewModel = scormContentData . FirstOrDefault < ContentServerViewModel > ( ) ;
80- return scormContentServerViewModel ;
81- }
79+ return scormContentServerViewModel ;
80+ }
8281
83- /// <inheritdoc/>
84- public async Task < List < string > > GetExternalReferenceByResourceId ( int resourceId )
85- {
86- return await ( from rr in this . DbContext . ResourceReference
87- join er in this . DbContext . ExternalReference on rr . Id equals er . ResourceReferenceId
88- where rr . ResourceId == resourceId
89- select er . Reference )
90- . ToListAsync ( ) ;
91- }
82+ /// <inheritdoc/>
83+ public async Task < List < string > > GetExternalReferenceByResourceId ( int resourceId )
84+ {
85+ return await ( from rr in this . DbContext . ResourceReference
86+ join er in this . DbContext . ExternalReference on rr . Id equals er . ResourceReferenceId
87+ where rr . ResourceId == resourceId
88+ select er . Reference )
89+ . ToListAsync ( ) ;
9290 }
91+ }
9392}
0 commit comments