diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Models/Configuration/LearningHubConfig.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Models/Configuration/LearningHubConfig.cs
index 6ccd4f37c..8030cdf7d 100644
--- a/OpenAPI/LearningHub.Nhs.OpenApi.Models/Configuration/LearningHubConfig.cs
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Models/Configuration/LearningHubConfig.cs
@@ -55,5 +55,75 @@ public class LearningHubConfig
///
public string ResourcePublishQueueRouteName { get; set; } = null!;
+ ///
+ /// Gets or sets .
+ ///
+ public NotificationSetting Notifications { get; set; } = null!;
+
+ ///
+ /// Gets or sets .
+ ///
+ public string MyContributionsUrl { get; set; } = null!;
+
+ ///
+ /// Gets or sets .
+ ///
+ public string MyLearningUrl { get; set; } = null!;
+
+ ///
+ /// Gets or sets .
+ ///
+ public string MyBookmarksUrl { get; set; } = null!;
+
+ ///
+ /// Gets or sets .
+ ///
+ public string SearchUrl { get; set; } = null!;
+
+ ///
+ /// Gets or sets .
+ ///
+ public string AdminUrl { get; set; } = null!;
+
+ ///
+ /// Gets or sets .
+ ///
+ public string ForumsUrl { get; set; } = null!;
+
+ ///
+ /// Gets or sets .
+ ///
+ public string HelpUrl { get; set; } = null!;
+
+ ///
+ /// Gets or sets .
+ ///
+ public string MyRecordsUrl { get; set; } = null!;
+
+ ///
+ /// Gets or sets .
+ ///
+ public string NotificationsUrl { get; set; } = null!;
+
+ ///
+ /// Gets or sets .
+ ///
+ public string RegisterUrl { get; set; } = null!;
+
+ ///
+ /// Gets or sets .
+ ///
+ public string SignOutUrl { get; set; } = null!;
+
+ ///
+ /// Gets or sets .
+ ///
+ public string MyAccountUrl { get; set; } = null!;
+
+ ///
+ /// Gets or sets .
+ ///
+ public string BrowseCataloguesUrl { get; set; } = null!;
+
}
}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Models/Configuration/NotificationSetting.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Models/Configuration/NotificationSetting.cs
new file mode 100644
index 000000000..7b9b7b5ba
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Models/Configuration/NotificationSetting.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace LearningHub.Nhs.OpenApi.Models.Configuration
+{
+ ///
+ /// Gets or sets NotificationSetting.
+ ///
+ public class NotificationSetting
+ {
+ ///
+ /// Gets or sets the PublishResourceTimeToProcessInSec.
+ ///
+ public int PublishResourceTimeToProcessInSec { get; set; }
+
+ ///
+ /// Gets or sets the ResourcePublishedTitle.
+ ///
+ public string ResourcePublishedTitle { get; set; } = null!;
+
+ ///
+ /// Gets or sets the ResourcePublished.
+ ///
+ public string ResourcePublished { get; set; } = null!;
+
+ ///
+ /// Gets or sets the ResourcePublishFailedTitle.
+ ///
+ public string ResourcePublishFailedTitle { get; set; } = null!;
+
+ ///
+ /// Gets or sets the ResourcePublishFailed.
+ ///
+ public string ResourcePublishFailed { get; set; } = null!;
+
+ ///
+ /// Gets or sets the ResourcePublishFailedWithReason.
+ ///
+ public string ResourcePublishFailedWithReason { get; set; } = null!;
+
+ ///
+ /// Gets or sets the ResourceAccessTitle.
+ ///
+ public string ResourceAccessTitle { get; set; } = null!;
+
+ ///
+ /// Gets or sets the ResourceReadonlyAccess.
+ ///
+ public string ResourceReadonlyAccess { get; set; } = null!;
+
+ ///
+ /// Gets or sets the ResourceContributeAccess.
+ ///
+ public string ResourceContributeAccess { get; set; } = null!;
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Models/ViewModels/NavigationModel.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Models/ViewModels/NavigationModel.cs
new file mode 100644
index 000000000..81f599c3f
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Models/ViewModels/NavigationModel.cs
@@ -0,0 +1,78 @@
+namespace LearningHub.Nhs.OpenApi.Models.ViewModels
+{
+ ///
+ /// Defines the .
+ ///
+ public class NavigationModel
+ {
+ ///
+ /// Gets or sets the NotificationCount.
+ ///
+ public int NotificationCount { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether ShowAdmin.
+ ///
+ public bool ShowAdmin { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether ShowForums.
+ ///
+ public bool ShowForums { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether ShowHelp.
+ ///
+ public bool ShowHelp { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether ShowMyContributions.
+ ///
+ public bool ShowMyContributions { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether ShowMyLearning.
+ ///
+ public bool ShowMyLearning { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether ShowMyBookmarks.
+ ///
+ public bool ShowMyBookmarks { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether ShowSearch.
+ ///
+ public bool ShowSearch { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether ShowMyRecords.
+ ///
+ public bool ShowMyRecords { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether ShowNotifications.
+ ///
+ public bool ShowNotifications { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether ShowRegister.
+ ///
+ public bool ShowRegister { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether ShowSignOut.
+ ///
+ public bool ShowSignOut { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether to show my account.
+ ///
+ public bool ShowMyAccount { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether to show Browse Catalogues.
+ ///
+ public bool ShowBrowseCatalogues { get; set; }
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/INotificationRepository.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/INotificationRepository.cs
new file mode 100644
index 000000000..a70a7f2e1
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/INotificationRepository.cs
@@ -0,0 +1,25 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Interface.Repositories
+{
+ using System.Linq;
+ using System.Threading.Tasks;
+ using LearningHub.Nhs.Models.Entities;
+
+ ///
+ /// The NotificationRepository interface.
+ ///
+ public interface INotificationRepository : IGenericRepository
+ {
+ ///
+ /// The get by id async.
+ ///
+ /// The id.
+ /// The .
+ Task GetByIdAsync(int id);
+
+ ///
+ /// The get all full.
+ ///
+ /// The .
+ IQueryable GetAllFull();
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/IResourceRepository.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/IResourceRepository.cs
index 1b9d45411..f340ce670 100644
--- a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/IResourceRepository.cs
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/IResourceRepository.cs
@@ -72,5 +72,12 @@ Task> GetResourceReferencesByOriginalResourceRefe
/// The .
Task GetByResourceVersionIdAsync(int resourceVersionId);
+ ///
+ /// Returns a bool to indicate if the resourceVersionId corresponds to a current version of a resource.
+ ///
+ /// The resourceVersionId.
+ /// The .
+ Task IsCurrentVersionAsync(int resourceVersionId);
+
}
}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/IUserNotificationRepository.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/IUserNotificationRepository.cs
new file mode 100644
index 000000000..b96401ba9
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/IUserNotificationRepository.cs
@@ -0,0 +1,45 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Interface.Repositories
+{
+ using System.Linq;
+ using System.Threading.Tasks;
+ using LearningHub.Nhs.Models.Entities;
+ using LearningHub.Nhs.Models.Enums;
+
+ ///
+ /// The UserNotificationRepository interface.
+ ///
+ public interface IUserNotificationRepository : IGenericRepository
+ {
+ ///
+ /// The get by id async.
+ ///
+ /// The id.
+ /// The .
+ Task GetByIdAsync(int id);
+
+ ///
+ /// The get by notification and user id async.
+ ///
+ /// The user id.
+ /// The notification id.
+ /// The .
+ Task GetByNotificationAndUserIdAsync(int userId, int notificationId);
+
+ ///
+ /// The get user unread notification count async.
+ ///
+ /// The userid.
+ /// The .
+ Task GetUserUnreadNotificationCountAsync(int userid);
+
+ ///
+ /// The get all non dismissed.
+ ///
+ /// The user id.
+ /// Notification priority type.
+ /// The sort column.
+ /// The sort direction.
+ /// The .
+ IQueryable GetAllNonDismissed(int userId, NotificationPriorityEnum priorityType, string sortColumn = "", string sortDirection = "");
+ }
+}
\ No newline at end of file
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/Resources/IResourceSyncRepository.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/Resources/IResourceSyncRepository.cs
new file mode 100644
index 000000000..98b1ea9e2
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/Resources/IResourceSyncRepository.cs
@@ -0,0 +1,44 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Interface.Repositories.Resources
+{
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Threading.Tasks;
+ using LearningHub.Nhs.Models.Entities.Resource;
+
+ ///
+ /// The IResourceSyncRepository.
+ ///
+ public interface IResourceSyncRepository
+ {
+ ///
+ /// The GetSyncListForUser.
+ ///
+ /// The userid.
+ /// If the resource property should be populated.
+ /// The sync list for the user.
+ IQueryable GetSyncListForUser(int userId, bool includeResources);
+
+ ///
+ /// The AddToSyncListAsync.
+ ///
+ /// The userId.
+ /// The resourceIds.
+ /// The task.
+ Task AddToSyncListAsync(int userId, List resourceIds);
+
+ ///
+ /// The RemoveFromSyncListAsync.
+ ///
+ /// The userId.
+ /// The resourceIds.
+ /// The task.
+ Task RemoveFromSyncListAsync(int userId, List resourceIds);
+
+ ///
+ /// The SetSyncedForUserAsync.
+ ///
+ /// The userId.
+ /// The task.
+ Task SetSyncedForUserAsync(int userId);
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/Resources/IResourceVersionRatingRepository.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/Resources/IResourceVersionRatingRepository.cs
new file mode 100644
index 000000000..aad4e49b7
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/Resources/IResourceVersionRatingRepository.cs
@@ -0,0 +1,26 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Interface.Repositories.Resources
+{
+ using System.Threading.Tasks;
+ using LearningHub.Nhs.Models.Entities.Resource;
+
+ ///
+ /// The ResourceVersionEventRepository interface.
+ ///
+ public interface IResourceVersionRatingRepository : IGenericRepository
+ {
+ ///
+ /// Gets a user's previous rating for any minor version of the current major resource version.
+ ///
+ /// The resourceVersionId.
+ /// The userId.
+ /// The .
+ Task GetUsersPreviousRatingForSameMajorVersionAsync(int resourceVersionId, int userId);
+
+ ///
+ /// Gets the total rating counts for a particular resource version PLUS all other minor versions of the same major version.
+ ///
+ /// The resourceVersionId.
+ /// An array of integers, which are the count for each star value, starting at 1 star and ending with 5 stars.
+ Task GetRatingCountsForResourceVersionAsync(int resourceVersionId);
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/Resources/IResourceVersionRatingSummaryRepository.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/Resources/IResourceVersionRatingSummaryRepository.cs
new file mode 100644
index 000000000..3fb2603f9
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/Resources/IResourceVersionRatingSummaryRepository.cs
@@ -0,0 +1,18 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Interface.Repositories.Resources
+{
+ using System.Threading.Tasks;
+ using LearningHub.Nhs.Models.Entities.Resource;
+
+ ///
+ /// The ResourceVersionEventRepository interface.
+ ///
+ public interface IResourceVersionRatingSummaryRepository : IGenericRepository
+ {
+ ///
+ /// The get by resource version id async.
+ ///
+ /// The resource version id.
+ /// The .
+ Task GetByResourceVersionIdAsync(int resourceVersionId);
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/EntityFramework/LearningHubDbContext.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/EntityFramework/LearningHubDbContext.cs
index 559f982e5..680d27ddb 100644
--- a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/EntityFramework/LearningHubDbContext.cs
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/EntityFramework/LearningHubDbContext.cs
@@ -24,7 +24,7 @@ namespace LearningHub.Nhs.OpenApi.Repositories.EntityFramework
///
/// The learning hub db context.
///
- public class LearningHubDbContext : DbContext
+ public partial class LearningHubDbContext : DbContext
{
///
/// The options..
@@ -41,6 +41,14 @@ public LearningHubDbContext(LearningHubDbContextOptions options)
this.options = options;
}
+ ///
+ /// Gets the Options.
+ ///
+ public LearningHubDbContextOptions Options
+ {
+ get { return this.options; }
+ }
+
///
/// Gets or sets the Address.
///
@@ -177,6 +185,11 @@ public LearningHubDbContext(LearningHubDbContextOptions options)
///
public virtual DbSet ResourceVersionValidationResult { get; set; }
+ ///
+ /// Gets or sets the resource version validation rule result.
+ ///
+ public virtual DbSet ResourceVersionValidationRuleResult { get; set; }
+
///
/// Gets or sets the resource version event..
///
@@ -466,6 +479,8 @@ public LearningHubDbContext(LearningHubDbContextOptions options)
///
public virtual DbSet CatalogueNodeVersion { get; set; }
+ public virtual DbSet CatalogueNodeVersionProvider { get; set; }
+
///
/// Gets or sets the catalogue node version keyword..
///
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/EntityFramework/ServiceMappings.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/EntityFramework/ServiceMappings.cs
index 8129bc9c8..964c7eac7 100644
--- a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/EntityFramework/ServiceMappings.cs
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/EntityFramework/ServiceMappings.cs
@@ -7,8 +7,10 @@ namespace LearningHub.Nhs.OpenApi.Repositories.EntityFramework
using LearningHub.Nhs.OpenApi.Repositories.Map.Content;
using LearningHub.Nhs.OpenApi.Repositories.Map.External;
using LearningHub.Nhs.OpenApi.Repositories.Map.Hierarchy;
+ using LearningHub.Nhs.OpenApi.Repositories.Map.Maintenance;
using LearningHub.Nhs.OpenApi.Repositories.Map.Messaging;
using LearningHub.Nhs.OpenApi.Repositories.Map.Resources;
+ using LearningHub.Nhs.OpenApi.Repositories.Map.Resources.Blocks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@@ -63,6 +65,7 @@ public static void AddLearningHubMappings(this IServiceCollection services, ICon
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
+ services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
@@ -77,11 +80,13 @@ public static void AddLearningHubMappings(this IServiceCollection services, ICon
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
+ services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
+ services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
@@ -95,6 +100,7 @@ public static void AddLearningHubMappings(this IServiceCollection services, ICon
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
+ services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
@@ -103,8 +109,14 @@ public static void AddLearningHubMappings(this IServiceCollection services, ICon
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
+ services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
@@ -123,6 +135,7 @@ public static void AddLearningHubMappings(this IServiceCollection services, ICon
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
+ services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
@@ -135,15 +148,21 @@ public static void AddLearningHubMappings(this IServiceCollection services, ICon
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
+ services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
+ services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
@@ -152,6 +171,7 @@ public static void AddLearningHubMappings(this IServiceCollection services, ICon
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
+ services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Activity/AssessmentResourceActivityMatchQuestionMap.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Activity/AssessmentResourceActivityMatchQuestionMap.cs
new file mode 100644
index 000000000..e9277cfac
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Activity/AssessmentResourceActivityMatchQuestionMap.cs
@@ -0,0 +1,39 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Map.Activity
+{
+ using LearningHub.Nhs.Models.Entities.Activity;
+ using Microsoft.EntityFrameworkCore;
+ using Microsoft.EntityFrameworkCore.Metadata.Builders;
+
+ ///
+ /// The resource activity match question map.
+ ///
+ public class AssessmentResourceActivityMatchQuestionMap : BaseEntityMap
+ {
+ ///
+ /// The internal map.
+ ///
+ /// The model builder.
+ protected override void InternalMap(EntityTypeBuilder modelBuilder)
+ {
+ modelBuilder.ToTable("AssessmentResourceActivityMatchQuestion", "activity");
+
+ modelBuilder.HasOne(e => e.AssessmentResourceActivity)
+ .WithMany(e => e.MatchQuestions)
+ .HasForeignKey(d => d.AssessmentResourceActivityId)
+ .OnDelete(DeleteBehavior.SetNull)
+ .HasConstraintName("FK_AssessmentResourceActivityMatchQuestion_AssessmentResourceActivityId");
+
+ modelBuilder.HasOne(e => e.FirstMatchAnswer)
+ .WithOne()
+ .HasForeignKey(d => d.FirstMatchAnswerId)
+ .OnDelete(DeleteBehavior.SetNull)
+ .HasConstraintName("FK_AssessmentResourceActivityMatchQuestion_FirstMatchAnswerId");
+
+ modelBuilder.HasOne(e => e.SecondMatchAnswer)
+ .WithOne()
+ .HasForeignKey(d => d.SecondMatchAnswerId)
+ .OnDelete(DeleteBehavior.SetNull)
+ .HasConstraintName("FK_AssessmentResourceActivityMatchQuestion_SecondMatchAnswerId");
+ }
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/EmailChangeValidationTokenMap.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/EmailChangeValidationTokenMap.cs
new file mode 100644
index 000000000..14406a08f
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/EmailChangeValidationTokenMap.cs
@@ -0,0 +1,23 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Map
+{
+ using LearningHub.Nhs.Models.Entities;
+ using Microsoft.EntityFrameworkCore;
+ using Microsoft.EntityFrameworkCore.Metadata.Builders;
+
+ ///
+ /// The email change validation token map.
+ ///
+ public class EmailChangeValidationTokenMap : BaseEntityMap
+ {
+ ///
+ /// The internal map.
+ ///
+ ///
+ /// The model builder.
+ ///
+ protected override void InternalMap(EntityTypeBuilder modelBuilder)
+ {
+ modelBuilder.ToTable("EmailChangeValidationToken", "hub");
+ }
+ }
+}
\ No newline at end of file
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Hierarchy/CatalogueNodeVersionProviderMap.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Hierarchy/CatalogueNodeVersionProviderMap.cs
new file mode 100644
index 000000000..0e3dedc5a
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Hierarchy/CatalogueNodeVersionProviderMap.cs
@@ -0,0 +1,28 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Map.Hierarchy
+{
+ using LearningHub.Nhs.Models.Entities.Hierarchy;
+ using Microsoft.EntityFrameworkCore;
+ using Microsoft.EntityFrameworkCore.Metadata.Builders;
+
+ ///
+ /// The CatalogueNodeVersionProviderMap.
+ ///
+ public class CatalogueNodeVersionProviderMap : BaseEntityMap
+ {
+ ///
+ /// The internal map.
+ ///
+ /// The modelBuilder.
+ protected override void InternalMap(EntityTypeBuilder modelBuilder)
+ {
+ modelBuilder.ToTable("CatalogueNodeVersionProvider", "hierarchy");
+ modelBuilder.HasKey(e => e.Id);
+ modelBuilder.Property(e => e.Id)
+ .HasColumnName("Id");
+ modelBuilder.Property(e => e.CatalogueNodeVersionId)
+ .HasColumnName("CatalogueNodeVersionId").IsRequired();
+ modelBuilder.Property(e => e.ProviderId).HasColumnName("ProviderId");
+ modelBuilder.Property(e => e.RemovalDate).HasColumnName("RemovalDate").IsRequired(false);
+ }
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Hierarchy/FolderNodeVersionMap.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Hierarchy/FolderNodeVersionMap.cs
new file mode 100644
index 000000000..6b2beab84
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Hierarchy/FolderNodeVersionMap.cs
@@ -0,0 +1,35 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Map.Hierarchy
+{
+ using LearningHub.Nhs.Models.Entities.Hierarchy;
+ using Microsoft.EntityFrameworkCore;
+ using Microsoft.EntityFrameworkCore.Metadata.Builders;
+
+ ///
+ /// The FolderNodeVersionMap.
+ ///
+ public class FolderNodeVersionMap : BaseEntityMap
+ {
+ ///
+ /// The internal map.
+ ///
+ /// The modelBuilder.
+ protected override void InternalMap(EntityTypeBuilder modelBuilder)
+ {
+ modelBuilder.ToTable("FolderNodeVersion", "hierarchy");
+
+ modelBuilder.Property(x => x.Name)
+ .IsRequired()
+ .HasMaxLength(255);
+
+ modelBuilder.Property(x => x.Description)
+ .IsRequired()
+ .HasMaxLength(1800);
+
+ modelBuilder.HasOne(d => d.NodeVersion)
+ .WithOne(p => p.FolderNodeVersion)
+ .HasForeignKey(d => d.NodeVersionId)
+ .OnDelete(DeleteBehavior.ClientSetNull)
+ .HasConstraintName("FK_FolderNodeVersion_NodeVersion");
+ }
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Hierarchy/HierarchyEditDetailMap.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Hierarchy/HierarchyEditDetailMap.cs
new file mode 100644
index 000000000..893fbfc25
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Hierarchy/HierarchyEditDetailMap.cs
@@ -0,0 +1,33 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Map.Hierarchy
+{
+ using LearningHub.Nhs.Models.Entities.Hierarchy;
+ using Microsoft.EntityFrameworkCore;
+ using Microsoft.EntityFrameworkCore.Metadata.Builders;
+
+ ///
+ /// The hierarchy edit map.
+ ///
+ public class HierarchyEditDetailMap : BaseEntityMap
+ {
+ ///
+ /// The internal map.
+ ///
+ /// The model builder.
+ protected override void InternalMap(EntityTypeBuilder modelBuilder)
+ {
+ modelBuilder.ToTable("HierarchyEditDetail", "hierarchy");
+
+ modelBuilder.HasOne(d => d.HierarchyEdit)
+ .WithMany(p => p.HierarchyEditDetail)
+ .HasForeignKey(d => d.HierarchyEditId)
+ .OnDelete(DeleteBehavior.ClientSetNull)
+ .HasConstraintName("FK_HierarchyEditDetail_HierarchyEdit");
+
+ modelBuilder.Property(e => e.HierarchyEditDetailType).HasColumnName("HierarchyEditDetailTypeId")
+ .HasConversion();
+
+ modelBuilder.Property(e => e.HierarchyEditDetailOperation).HasColumnName("HierarchyEditDetailOperationId")
+ .HasConversion();
+ }
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Hierarchy/HierarchyEditMap.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Hierarchy/HierarchyEditMap.cs
new file mode 100644
index 000000000..23883290e
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Hierarchy/HierarchyEditMap.cs
@@ -0,0 +1,41 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Map.Hierarchy
+{
+ using LearningHub.Nhs.Models.Entities.Hierarchy;
+ using Microsoft.EntityFrameworkCore;
+ using Microsoft.EntityFrameworkCore.Metadata.Builders;
+
+ ///
+ /// The hierarchy edit map.
+ ///
+ public class HierarchyEditMap : BaseEntityMap
+ {
+ ///
+ /// The internal map.
+ ///
+ /// The model builder.
+ protected override void InternalMap(EntityTypeBuilder modelBuilder)
+ {
+ modelBuilder.ToTable("HierarchyEdit", "hierarchy");
+
+ modelBuilder.Property(e => e.HierarchyEditStatus).HasColumnName("HierarchyEditStatusId")
+ .HasConversion();
+
+ modelBuilder.HasOne(d => d.CreateUser)
+ .WithMany(p => p.HierarchyEdit)
+ .HasForeignKey(d => d.CreateUserId)
+ .OnDelete(DeleteBehavior.ClientSetNull)
+ .HasConstraintName("FK_HierarchyEdit_CreateUser");
+
+ modelBuilder.HasOne(d => d.RootNode)
+ .WithMany()
+ .HasForeignKey(d => d.RootNodeId)
+ .HasConstraintName("FK_HierarchyEdit_Node");
+
+ modelBuilder.HasOne(d => d.Publication)
+ .WithMany()
+ .HasForeignKey(d => d.PublicationId)
+ .OnDelete(DeleteBehavior.ClientSetNull)
+ .HasConstraintName("FK_HierarchyEdit_Publication");
+ }
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Hierarchy/NodeResourceLookupMap.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Hierarchy/NodeResourceLookupMap.cs
new file mode 100644
index 000000000..d0d98093f
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Hierarchy/NodeResourceLookupMap.cs
@@ -0,0 +1,33 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Map.Hierarchy
+{
+ using LearningHub.Nhs.Models.Entities.Hierarchy;
+ using Microsoft.EntityFrameworkCore;
+ using Microsoft.EntityFrameworkCore.Metadata.Builders;
+
+ ///
+ /// The node resource lookup map.
+ ///
+ public class NodeResourceLookupMap : BaseEntityMap
+ {
+ ///
+ /// The internal map.
+ ///
+ /// The model builder.
+ protected override void InternalMap(EntityTypeBuilder modelBuilder)
+ {
+ modelBuilder.ToTable("NodeResourceLookup", "hierarchy");
+
+ modelBuilder.HasOne(d => d.Node)
+ .WithMany()
+ .HasForeignKey(d => d.NodeId)
+ .OnDelete(DeleteBehavior.ClientSetNull)
+ .HasConstraintName("FK_NodeResourceLookup_Node");
+
+ modelBuilder.HasOne(d => d.Resource)
+ .WithMany()
+ .HasForeignKey(d => d.ResourceId)
+ .OnDelete(DeleteBehavior.ClientSetNull)
+ .HasConstraintName("FK_NodeResourceLookup_Resource");
+ }
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Maintenance/InternalSystemMap.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Maintenance/InternalSystemMap.cs
new file mode 100644
index 000000000..6da03f6fd
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Maintenance/InternalSystemMap.cs
@@ -0,0 +1,32 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Map.Maintenance
+{
+ using LearningHub.Nhs.Models.Entities.Maintenance;
+ using Microsoft.EntityFrameworkCore;
+ using Microsoft.EntityFrameworkCore.Metadata.Builders;
+
+ ///
+ /// Defines the .
+ ///
+ public class InternalSystemMap : BaseEntityMap
+ {
+ ///
+ /// The InternalMap.
+ ///
+ /// The entity.
+ protected override void InternalMap(EntityTypeBuilder entity)
+ {
+ entity.ToTable("InternalSystem", "maintenance");
+
+ entity.HasIndex(e => e.Name)
+ .IsUnique();
+
+ entity.Property(e => e.Name)
+ .IsRequired()
+ .HasMaxLength(50);
+
+ entity.Property(e => e.Description)
+ .IsRequired()
+ .HasMaxLength(2000);
+ }
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/ProviderMap.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/ProviderMap.cs
new file mode 100644
index 000000000..0f0f5af2d
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/ProviderMap.cs
@@ -0,0 +1,39 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Map
+{
+ using LearningHub.Nhs.Models.Entities;
+ using Microsoft.EntityFrameworkCore;
+ using Microsoft.EntityFrameworkCore.Metadata.Builders;
+
+ ///
+ /// The provider map.
+ ///
+ public class ProviderMap : BaseEntityMap
+ {
+ ///
+ /// The internal map.
+ ///
+ /// The model builder.
+ protected override void InternalMap(EntityTypeBuilder modelBuilder)
+ {
+ modelBuilder.ToTable("Provider", "hub");
+
+ modelBuilder.HasKey(e => e.Id);
+
+ modelBuilder.Property(e => e.Id)
+ .HasColumnName("Id");
+
+ modelBuilder.Property(e => e.Description)
+ .HasColumnName("Description")
+ .HasMaxLength(255);
+
+ modelBuilder.Property(e => e.Logo)
+ .HasColumnName("Logo")
+ .HasMaxLength(100);
+
+ modelBuilder.Property(e => e.Name)
+ .IsRequired()
+ .HasColumnName("Name")
+ .HasMaxLength(255);
+ }
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/Blocks/WholeSlideImageAnnotationMap.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/Blocks/ImageAnnotationMap.cs
similarity index 65%
rename from OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/Blocks/WholeSlideImageAnnotationMap.cs
rename to OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/Blocks/ImageAnnotationMap.cs
index 00f7f46cb..fd31afb51 100644
--- a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/Blocks/WholeSlideImageAnnotationMap.cs
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/Blocks/ImageAnnotationMap.cs
@@ -1,20 +1,18 @@
-namespace LearningHub.Nhs.OpenApi.Repositories.Map.Resources
+namespace LearningHub.Nhs.OpenApi.Repositories.Map.Resources.Blocks
{
using LearningHub.Nhs.Models.Entities.Resource;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
///
- /// The whole slide image annotation map.
+ /// The image annotation map.
///
public class ImageAnnotationMap : BaseEntityMap
{
///
/// The internal map.
///
- ///
- /// The model builder.
- ///
+ /// The model builder.
protected override void InternalMap(EntityTypeBuilder modelBuilder)
{
modelBuilder.ToTable("ImageAnnotation", "resources");
@@ -24,6 +22,12 @@ protected override void InternalMap(EntityTypeBuilder modelBuil
.HasForeignKey(a => a.WholeSlideImageId)
.OnDelete(DeleteBehavior.Cascade)
.HasConstraintName("FK_ImageAnnotation_WholeSlideImageId");
+
+ modelBuilder.HasOne(a => a.Image)
+ .WithMany(i => i.ImageAnnotations)
+ .HasForeignKey(a => a.ImageId)
+ .OnDelete(DeleteBehavior.Cascade)
+ .HasConstraintName("FK_ImageAnnotation_ImageId");
}
}
}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/Blocks/WholeSlideImageAnnotationMarkMap.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/Blocks/ImageAnnotationMarkMap.cs
similarity index 80%
rename from OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/Blocks/WholeSlideImageAnnotationMarkMap.cs
rename to OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/Blocks/ImageAnnotationMarkMap.cs
index 9db0a6db6..a1bad42e9 100644
--- a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/Blocks/WholeSlideImageAnnotationMarkMap.cs
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/Blocks/ImageAnnotationMarkMap.cs
@@ -1,20 +1,18 @@
-namespace LearningHub.Nhs.OpenApi.Repositories.Map.Resources
+namespace LearningHub.Nhs.OpenApi.Repositories.Map.Resources.Blocks
{
using LearningHub.Nhs.Models.Entities.Resource;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
///
- /// The whole slide image annotation map.
+ /// The image annotation mark map.
///
public class ImageAnnotationMarkMap : BaseEntityMap
{
///
/// The internal map.
///
- ///
- /// The model builder.
- ///
+ /// The model builder.
protected override void InternalMap(EntityTypeBuilder modelBuilder)
{
modelBuilder.ToTable("ImageAnnotationMark", "resources");
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/Blocks/ImageCarouselBlockMap.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/Blocks/ImageCarouselBlockMap.cs
new file mode 100644
index 000000000..706269026
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/Blocks/ImageCarouselBlockMap.cs
@@ -0,0 +1,36 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Map.Resources.Blocks
+{
+ using LearningHub.Nhs.Models.Entities.Resource.Blocks;
+ using Microsoft.EntityFrameworkCore;
+ using Microsoft.EntityFrameworkCore.Metadata.Builders;
+
+ ///
+ /// the image carousel block map.
+ ///
+ public class ImageCarouselBlockMap : BaseEntityMap
+ {
+ ///
+ /// The internal map.
+ ///
+ /// The model builder.
+ protected override void InternalMap(EntityTypeBuilder modelBuilder)
+ {
+ modelBuilder.ToTable("ImageCarouselBlock", "resources");
+
+ modelBuilder.Property(e => e.BlockId).ValueGeneratedNever();
+ modelBuilder.HasAlternateKey(c => c.BlockId);
+
+ modelBuilder.HasOne(d => d.Block)
+ .WithOne(p => p.ImageCarouselBlock)
+ .HasForeignKey(d => d.BlockId)
+ .OnDelete(DeleteBehavior.Cascade)
+ .HasConstraintName("FK_ImageCarouselBlock_BlockId");
+
+ modelBuilder.HasOne(d => d.ImageBlockCollection)
+ .WithOne()
+ .HasForeignKey(d => d.ImageBlockCollectionId)
+ .OnDelete(DeleteBehavior.Cascade)
+ .HasConstraintName("FK_ImageCarouselBlock_ImageBlockCollectionId");
+ }
+ }
+}
\ No newline at end of file
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/HtmlResourceVersionMap.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/HtmlResourceVersionMap.cs
new file mode 100644
index 000000000..b9608cbec
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/HtmlResourceVersionMap.cs
@@ -0,0 +1,40 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Map.Resources
+{
+ using LearningHub.Nhs.Models.Entities.Resource;
+ using LearningHub.Nhs.OpenApi.Repositories.Map;
+ using Microsoft.EntityFrameworkCore;
+ using Microsoft.EntityFrameworkCore.Metadata.Builders;
+
+ ///
+ /// The html resource version map.
+ ///
+ public class HtmlResourceVersionMap : BaseEntityMap
+ {
+ ///
+ /// The internal map.
+ ///
+ /// The model builder.
+ protected override void InternalMap(EntityTypeBuilder modelBuilder)
+ {
+ modelBuilder.HasKey(e => e.Id)
+ .HasName("PK_Resources_HtmlResourceVersion");
+
+ modelBuilder.ToTable("HtmlResourceVersion", "resources");
+
+ modelBuilder.Property(e => e.ResourceVersionId).ValueGeneratedNever();
+ modelBuilder.HasAlternateKey(c => c.ResourceVersionId);
+
+ modelBuilder.HasOne(d => d.File)
+ .WithMany(p => p.HtmlResourceVersion)
+ .HasForeignKey(d => d.FileId)
+ .OnDelete(DeleteBehavior.ClientSetNull)
+ .HasConstraintName("FK_HtmlResource_File");
+
+ modelBuilder.HasOne(d => d.ResourceVersion)
+ .WithOne(p => p.HtmlResourceVersion)
+ .HasForeignKey(d => d.ResourceVersionId)
+ .OnDelete(DeleteBehavior.ClientSetNull)
+ .HasConstraintName("FK_HtmlResourceVersion_ResourceVersion");
+ }
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/ResourceVersionProviderMap.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/ResourceVersionProviderMap.cs
new file mode 100644
index 000000000..563e9dd3b
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/ResourceVersionProviderMap.cs
@@ -0,0 +1,35 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Map.Resources
+{
+ using LearningHub.Nhs.Models.Entities.Resource;
+ using Microsoft.EntityFrameworkCore;
+ using Microsoft.EntityFrameworkCore.Metadata.Builders;
+
+ ///
+ /// The resource version provider map.
+ ///
+ public class ResourceVersionProviderMap : BaseEntityMap
+ {
+ ///
+ /// The internal map.
+ ///
+ /// The model builder.
+ protected override void InternalMap(EntityTypeBuilder modelBuilder)
+ {
+ modelBuilder.ToTable("ResourceVersionProvider", "resources");
+ modelBuilder.Property(e => e.ProviderId).HasColumnName("ProviderId");
+ modelBuilder.Property(e => e.ResourceVersionId).HasColumnName("ResourceVersionId");
+
+ modelBuilder.HasOne(d => d.ResourceVersion)
+ .WithMany(p => p.ResourceVersionProvider)
+ .HasForeignKey(d => d.ResourceVersionId)
+ .OnDelete(DeleteBehavior.ClientSetNull)
+ .HasConstraintName("FK_resourceVersionProvider_resourceVersion");
+
+ modelBuilder.HasOne(d => d.Provider)
+ .WithMany(p => p.ResourceVersionProvider)
+ .HasForeignKey(d => d.ProviderId)
+ .OnDelete(DeleteBehavior.ClientSetNull)
+ .HasConstraintName("FK_resourceVersionProvider_provider");
+ }
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/ResourceVersionValidationResultMap.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/ResourceVersionValidationResultMap.cs
index dc0bbfaba..e62ee5858 100644
--- a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/ResourceVersionValidationResultMap.cs
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/Resources/ResourceVersionValidationResultMap.cs
@@ -22,12 +22,6 @@ protected override void InternalMap(EntityTypeBuilder d.ResourceVersion)
- .WithMany()
- .HasForeignKey(d => d.ResourceVersionId)
- .OnDelete(DeleteBehavior.ClientSetNull)
- .HasConstraintName("FK_ResourceVersionValidationResult_ResourceVersion");
-
modelBuilder.Property(e => e.Details)
.IsRequired()
.HasMaxLength(1024);
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/UserBookmarkMap.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/UserBookmarkMap.cs
new file mode 100644
index 000000000..87d2a23be
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Map/UserBookmarkMap.cs
@@ -0,0 +1,21 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Map
+{
+ using LearningHub.Nhs.Models.Entities;
+ using Microsoft.EntityFrameworkCore;
+ using Microsoft.EntityFrameworkCore.Metadata.Builders;
+
+ ///
+ /// Defines the .
+ ///
+ public class UserBookmarkMap : BaseEntityMap
+ {
+ ///
+ /// The internal map.
+ ///
+ /// The modelBuilder.
+ protected override void InternalMap(EntityTypeBuilder modelBuilder)
+ {
+ modelBuilder.ToTable("UserBookmark", "hub");
+ }
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/GenericRepository.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/GenericRepository.cs
index cff356d60..08a8051a2 100644
--- a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/GenericRepository.cs
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/GenericRepository.cs
@@ -22,8 +22,8 @@ public class GenericRepository : IGenericRepository
/// The Timezone offset manager.
public GenericRepository(LearningHubDbContext dbContext, ITimezoneOffsetManager tzOffsetManager)
{
- DbContext = dbContext;
- TimezoneOffsetManager = tzOffsetManager;
+ this.DbContext = dbContext;
+ this.TimezoneOffsetManager = tzOffsetManager;
}
///
@@ -42,7 +42,7 @@ public GenericRepository(LearningHubDbContext dbContext, ITimezoneOffsetManager
/// The .
public IQueryable GetAll()
{
- return DbContext.Set().AsNoTracking();
+ return this.DbContext.Set().AsNoTracking();
}
///
@@ -53,18 +53,18 @@ public IQueryable GetAll()
/// The .
public virtual async Task CreateAsync(int userId, TEntity entity)
{
- await DbContext.Set().AddAsync(entity);
- SetAuditFieldsForCreate(userId, entity);
+ await this.DbContext.Set().AddAsync(entity);
+ this.SetAuditFieldsForCreate(userId, entity);
try
{
- await DbContext.SaveChangesAsync();
+ await this.DbContext.SaveChangesAsync();
}
catch (Exception)
{
throw;
}
- DbContext.Entry(entity).State = EntityState.Detached;
+ this.DbContext.Entry(entity).State = EntityState.Detached;
return entity.Id;
}
@@ -77,13 +77,13 @@ public virtual async Task CreateAsync(int userId, TEntity entity)
/// The .
public virtual async Task UpdateAsync(int userId, TEntity entity)
{
- DbContext.Set().Update(entity);
+ this.DbContext.Set().Update(entity);
- SetAuditFieldsForUpdate(userId, entity);
+ this.SetAuditFieldsForUpdate(userId, entity);
- await DbContext.SaveChangesAsync();
+ await this.DbContext.SaveChangesAsync();
- DbContext.Entry(entity).State = EntityState.Detached;
+ this.DbContext.Entry(entity).State = EntityState.Detached;
}
///
@@ -93,13 +93,13 @@ public virtual async Task UpdateAsync(int userId, TEntity entity)
/// The entity.
public virtual void Update(int userId, TEntity entity)
{
- DbContext.Set().Update(entity);
+ this.DbContext.Set().Update(entity);
- SetAuditFieldsForUpdate(userId, entity);
+ this.SetAuditFieldsForUpdate(userId, entity);
- DbContext.SaveChanges();
+ this.DbContext.SaveChanges();
- DbContext.Entry(entity).State = EntityState.Detached;
+ this.DbContext.Entry(entity).State = EntityState.Detached;
}
///
@@ -109,7 +109,7 @@ public virtual void Update(int userId, TEntity entity)
/// The entity.
public void SetAuditFieldsForCreate(int userId, EntityBase entity)
{
- var amendDate = GetAmendDate();
+ var amendDate = this.GetAmendDate();
entity.Deleted = false;
entity.CreateUserId = userId;
@@ -128,11 +128,11 @@ public void SetAuditFieldsForCreateOrDelete(int userId, EntityBase entity, bool
{
if (isCreate)
{
- SetAuditFieldsForCreate(userId, entity);
+ this.SetAuditFieldsForCreate(userId, entity);
}
else
{
- SetAuditFieldsForDelete(userId, entity);
+ this.SetAuditFieldsForDelete(userId, entity);
}
}
@@ -144,13 +144,13 @@ public void SetAuditFieldsForCreateOrDelete(int userId, EntityBase entity, bool
public void SetAuditFieldsForUpdate(int userId, EntityBase entity)
{
entity.AmendUserId = userId;
- entity.AmendDate = GetAmendDate();
- DbContext.Entry(entity).Property("CreateUserId").IsModified = false;
- DbContext.Entry(entity).Property("CreateDate").IsModified = false;
+ entity.AmendDate = this.GetAmendDate();
+ this.DbContext.Entry(entity).Property("CreateUserId").IsModified = false;
+ this.DbContext.Entry(entity).Property("CreateDate").IsModified = false;
if (entity.GetType() == typeof(User))
{
- DbContext.Entry(entity).Property("VersionStartTime").IsModified = false;
- DbContext.Entry(entity).Property("VersionEndTime").IsModified = false;
+ this.DbContext.Entry(entity).Property("VersionStartTime").IsModified = false;
+ this.DbContext.Entry(entity).Property("VersionEndTime").IsModified = false;
}
}
@@ -163,14 +163,14 @@ public void SetAuditFieldsForDelete(int userId, EntityBase entity)
{
entity.Deleted = true;
entity.AmendUserId = userId;
- entity.AmendDate = GetAmendDate();
- DbContext.Entry(entity).Property("CreateUserId").IsModified = false;
- DbContext.Entry(entity).Property("CreateDate").IsModified = false;
+ entity.AmendDate = this.GetAmendDate();
+ this.DbContext.Entry(entity).Property("CreateUserId").IsModified = false;
+ this.DbContext.Entry(entity).Property("CreateDate").IsModified = false;
}
private DateTimeOffset GetAmendDate()
{
- var tzOffset = TimezoneOffsetManager.UserTimezoneOffset;
+ var tzOffset = this.TimezoneOffsetManager.UserTimezoneOffset;
return tzOffset.HasValue ? new DateTimeOffset(DateTime.UtcNow.AddMinutes(tzOffset.Value).Ticks, TimeSpan.FromMinutes(tzOffset.Value)) : DateTimeOffset.Now;
}
}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/NotificationRepository.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/NotificationRepository.cs
new file mode 100644
index 000000000..71f9335f8
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/NotificationRepository.cs
@@ -0,0 +1,52 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Repositories
+{
+ using System.Linq;
+ using System.Threading.Tasks;
+ using LearningHub.Nhs.Models.Entities;
+ using LearningHub.Nhs.OpenApi.Repositories.EntityFramework;
+ using LearningHub.Nhs.OpenApi.Repositories.Interface.Repositories;
+ using Microsoft.EntityFrameworkCore;
+
+ ///
+ /// The notification repository.
+ ///
+ public class NotificationRepository : GenericRepository, INotificationRepository
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The db context.
+ /// The Timezone offset manager.
+ public NotificationRepository(LearningHubDbContext dbContext, ITimezoneOffsetManager tzOffsetManager)
+ : base(dbContext, tzOffsetManager)
+ {
+ }
+
+ ///
+ /// The get by id async.
+ ///
+ /// The id.
+ /// The .
+ public Task GetByIdAsync(int id)
+ {
+ return DbContext.Notification
+ .Include(n => n.AmendUser)
+ .Include(n => n.CreateUser)
+ .Where(n => n.Id == id)
+ .AsNoTracking()
+ .SingleOrDefaultAsync();
+ }
+
+ ///
+ /// The get all full.
+ ///
+ /// The .
+ public IQueryable GetAllFull()
+ {
+ return DbContext.Set()
+ .Include(n => n.AmendUser)
+ .Include(n => n.CreateUser)
+ .AsNoTracking();
+ }
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/ResourceRepository.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/ResourceRepository.cs
index deef84ccb..a0004a6e2 100644
--- a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/ResourceRepository.cs
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/ResourceRepository.cs
@@ -16,7 +16,6 @@ namespace LearningHub.Nhs.OpenApi.Repositories.Repositories
///
public class ResourceRepository : GenericRepository, IResourceRepository
{
-
///
/// Initializes a new instance of the class.
///
@@ -187,5 +186,16 @@ public async Task GetByResourceVersionIdAsync(int resourceVersionId)
}
+ ///
+ /// Returns a bool to indicate if the resourceVersionId corresponds to a current version of a resource.
+ ///
+ /// The resourceVersionId.
+ /// The .
+ public async Task IsCurrentVersionAsync(int resourceVersionId)
+ {
+ return await this.DbContext.Resource.AnyAsync(r => r.CurrentResourceVersionId == resourceVersionId && !r.Deleted);
+ }
+
+
}
}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/HtmlResourceVersionRepository.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/HtmlResourceVersionRepository.cs
index e12ff8f6e..3f1cffcc2 100644
--- a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/HtmlResourceVersionRepository.cs
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/HtmlResourceVersionRepository.cs
@@ -30,7 +30,7 @@ public HtmlResourceVersionRepository(LearningHubDbContext dbContext, ITimezoneOf
/// The .
public async Task GetByIdAsync(int id)
{
- return await DbContext.HtmlResourceVersion.AsNoTracking().FirstOrDefaultAsync(r => r.Id == id && !r.Deleted);
+ return await this.DbContext.HtmlResourceVersion.AsNoTracking().FirstOrDefaultAsync(r => r.Id == id && !r.Deleted);
}
///
@@ -41,7 +41,7 @@ public async Task GetByIdAsync(int id)
/// The .
public async Task GetByResourceVersionIdAsync(int resourceVersionid, bool includeDeleted = false)
{
- return await DbContext.HtmlResourceVersion
+ return await this.DbContext.HtmlResourceVersion
.Include(gfrv => gfrv.File).ThenInclude(f => f.FileType)
.AsNoTracking().FirstOrDefaultAsync(gfrv => gfrv.ResourceVersionId == resourceVersionid && (includeDeleted || !gfrv.Deleted));
}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/ResourceSyncRepository.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/ResourceSyncRepository.cs
new file mode 100644
index 000000000..b4fa27438
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/ResourceSyncRepository.cs
@@ -0,0 +1,105 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Repositories.Resources
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Threading.Tasks;
+ using LearningHub.Nhs.Models.Entities.Resource;
+ using LearningHub.Nhs.OpenApi.Repositories.EntityFramework;
+ using LearningHub.Nhs.OpenApi.Repositories.Interface.Repositories;
+ using LearningHub.Nhs.OpenApi.Repositories.Interface.Repositories.Resources;
+ using Microsoft.EntityFrameworkCore;
+
+ ///
+ /// The resource sync repository.
+ ///
+ public class ResourceSyncRepository : GenericRepository, IResourceSyncRepository
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The dbcontext.
+ /// The Timezone offset manager.
+ public ResourceSyncRepository(LearningHubDbContext dbContext, ITimezoneOffsetManager tzOffsetManager)
+ : base(dbContext, tzOffsetManager)
+ {
+ }
+
+ ///
+ /// The GetSyncListForUser.
+ ///
+ /// The userid.
+ /// If the resource property should be populated.
+ /// The sync list for the user.
+ public IQueryable GetSyncListForUser(int userId, bool includeResources)
+ {
+ var resourceSyncs = GetAll();
+ if (includeResources)
+ {
+ resourceSyncs = resourceSyncs
+ .Include(x => x.Resource).ThenInclude(x => x.CreateUser)
+ .Include(x => x.Resource).ThenInclude(x => x.Resource).ThenInclude(r => r.ResourceReference)
+ .Include(x => x.Resource).ThenInclude(x => x.ResourceVersionKeyword)
+ .Include(x => x.Resource).ThenInclude(x => x.ResourceVersionAuthor)
+ .Include(x => x.Resource).ThenInclude(x => x.ResourceVersionRatingSummary)
+ .Include(x => x.Resource).ThenInclude(x => x.Publication);
+ }
+
+ return resourceSyncs.Where(x => x.UserId == userId);
+ }
+
+ ///
+ /// The AddToSyncListAsync.
+ ///
+ /// The userId.
+ /// The resourceIds.
+ /// The task.
+ public async Task AddToSyncListAsync(int userId, List resourceIds)
+ {
+ foreach (var resourceId in resourceIds)
+ {
+ var resourceSync = new ResourceSync { ResourceId = resourceId, UserId = userId };
+ await CreateAsync(userId, resourceSync);
+ }
+ }
+
+ ///
+ /// The RemoveFromSyncListAsync.
+ ///
+ /// The userId.
+ /// The resourceIds.
+ /// The task.
+ public async Task RemoveFromSyncListAsync(int userId, List resourceIds)
+ {
+ var syncsToRemove = GetAll().Where(x => x.UserId == userId && resourceIds.Contains(x.ResourceId)).ToList();
+ foreach (var sync in syncsToRemove)
+ {
+ SetAuditFieldsForDelete(userId, sync);
+ try
+ {
+ await UpdateAsync(userId, sync);
+ }
+ catch (Exception ex)
+ {
+ var a = ex;
+ throw a;
+ }
+ }
+ }
+
+ ///
+ /// The SetSyncedForUserAsync.
+ ///
+ /// The userId.
+ /// The task.
+ public async Task SetSyncedForUserAsync(int userId)
+ {
+ var resourceSyncs = GetSyncListForUser(userId, false).ToList();
+ foreach (var sync in resourceSyncs)
+ {
+ SetAuditFieldsForDelete(userId, sync);
+ await UpdateAsync(userId, sync);
+ }
+ }
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/ResourceVersionRatingRepository.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/ResourceVersionRatingRepository.cs
new file mode 100644
index 000000000..d332fcd52
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/ResourceVersionRatingRepository.cs
@@ -0,0 +1,77 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Repositories.Resources
+{
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Threading.Tasks;
+ using LearningHub.Nhs.Models.Entities.Resource;
+ using LearningHub.Nhs.OpenApi.Repositories.EntityFramework;
+ using LearningHub.Nhs.OpenApi.Repositories.Interface.Repositories;
+ using LearningHub.Nhs.OpenApi.Repositories.Interface.Repositories.Resources;
+ using Microsoft.EntityFrameworkCore;
+
+ ///
+ /// The resource version Event repository.
+ ///
+ public class ResourceVersionRatingRepository : GenericRepository, IResourceVersionRatingRepository
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The db context.
+ /// The Timezone offset manager.
+ public ResourceVersionRatingRepository(LearningHubDbContext dbContext, ITimezoneOffsetManager tzOffsetManager)
+ : base(dbContext, tzOffsetManager)
+ {
+ }
+
+ ///
+ /// Gets a user's previous rating for any minor version of the same major resource version.
+ ///
+ /// The resourceVersionId.
+ /// The userId.
+ /// The .
+ public async Task GetUsersPreviousRatingForSameMajorVersionAsync(int resourceVersionId, int userId)
+ {
+ var minorVersionIds = await GetAllResourceVersionIdsForSameMajorVersion(resourceVersionId);
+
+ return await DbContext.ResourceVersionRating.FirstOrDefaultAsync(x => minorVersionIds.Contains(x.ResourceVersionId) && x.UserId == userId && !x.Deleted);
+ }
+
+ ///
+ /// Gets the total rating counts across all users for a particular resource version.
+ ///
+ /// The resourceVersionId.
+ /// An array of integers, which are the count for each star value, starting at 1 star and ending with 5 stars.
+ public async Task GetRatingCountsForResourceVersionAsync(int resourceVersionId)
+ {
+ var minorVersionIds = await GetAllResourceVersionIdsForSameMajorVersion(resourceVersionId);
+
+ var allMajorVersionRatings = DbContext.ResourceVersionRating.Where(x => minorVersionIds.Contains(x.ResourceVersionId));
+
+ int[] starCounts = new int[5];
+
+ starCounts[0] = await allMajorVersionRatings.CountAsync(x => x.Rating == 1);
+ starCounts[1] = await allMajorVersionRatings.CountAsync(x => x.Rating == 2);
+ starCounts[2] = await allMajorVersionRatings.CountAsync(x => x.Rating == 3);
+ starCounts[3] = await allMajorVersionRatings.CountAsync(x => x.Rating == 4);
+ starCounts[4] = await allMajorVersionRatings.CountAsync(x => x.Rating == 5);
+
+ return starCounts;
+ }
+
+ ///
+ /// Gets a list of resource version Ids for ALL minor versions of the same major resource version.
+ ///
+ /// The resource version id.
+ /// A list of resoruce verison ids.
+ private async Task> GetAllResourceVersionIdsForSameMajorVersion(int resourceVersionId)
+ {
+ var majorVersionInfo = await DbContext.ResourceVersion.Where(x => x.Id == resourceVersionId).Select(x => new { x.ResourceId, x.MajorVersion }).FirstOrDefaultAsync();
+
+ var minorVersionIds = await DbContext.ResourceVersion
+ .Where(x => x.ResourceId == majorVersionInfo.ResourceId && x.MajorVersion == majorVersionInfo.MajorVersion).Select(x => x.Id).ToListAsync();
+
+ return minorVersionIds;
+ }
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/ResourceVersionRatingSummaryRepository.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/ResourceVersionRatingSummaryRepository.cs
new file mode 100644
index 000000000..34bf3358d
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/ResourceVersionRatingSummaryRepository.cs
@@ -0,0 +1,37 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Repositories.Resources
+{
+ using System.Linq;
+ using System.Threading.Tasks;
+ using LearningHub.Nhs.Models.Entities.Resource;
+ using LearningHub.Nhs.OpenApi.Repositories.EntityFramework;
+ using LearningHub.Nhs.OpenApi.Repositories.Interface.Repositories;
+ using LearningHub.Nhs.OpenApi.Repositories.Interface.Repositories.Resources;
+ using Microsoft.EntityFrameworkCore;
+
+ ///
+ /// The resource version rating summary repository.
+ ///
+ public class ResourceVersionRatingSummaryRepository : GenericRepository, IResourceVersionRatingSummaryRepository
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The db context.
+ /// The Timezone offset manager.
+ public ResourceVersionRatingSummaryRepository(LearningHubDbContext dbContext, ITimezoneOffsetManager tzOffsetManager)
+ : base(dbContext, tzOffsetManager)
+ {
+ }
+
+ ///
+ /// The get by resource version id async.
+ ///
+ /// The resource version id.
+ /// The .
+ public Task GetByResourceVersionIdAsync(int resourceVersionId)
+ {
+ return DbContext.ResourceVersionRatingSummary.Where(r => r.ResourceVersionId == resourceVersionId && !r.Deleted).AsNoTracking()
+ .SingleOrDefaultAsync();
+ }
+ }
+}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/ResourceVersionRepository.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/ResourceVersionRepository.cs
index 6ead541f8..be139ffc8 100644
--- a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/ResourceVersionRepository.cs
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/ResourceVersionRepository.cs
@@ -38,7 +38,7 @@ public ResourceVersionRepository(LearningHubDbContext dbContext, ITimezoneOffset
/// The .
public IQueryable GetAllAdminSearch(int userId)
{
- return DbContext.Set()
+ return this.DbContext.Set()
.Include(r => r.Resource)
.ThenInclude(r => r.ResourceReference)
.Include(n => n.CreateUser)
@@ -59,7 +59,7 @@ public IQueryable GetAllAdminSearch(int userId)
/// The resource version list.
public async Task> GetResourceVersionsForSearchSubmission(List resourceVersionIds)
{
- return await DbContext.ResourceVersion
+ return await this.DbContext.ResourceVersion
.Include(x => x.Resource).ThenInclude(r => r.ResourceReference)
.Include(x => x.ResourceVersionKeyword)
.Include(x => x.ResourceVersionAuthor)
@@ -81,7 +81,7 @@ public async Task> GetResourceVersionsForSearchSubmission(
/// The .
public async Task GetBasicByIdAsync(int id)
{
- return await DbContext.ResourceVersion
+ return await this.DbContext.ResourceVersion
.Include(rv => rv.Resource)
.ThenInclude(r => r.CurrentResourceVersion)
.Include(rv => rv.Resource)
@@ -105,7 +105,7 @@ public async Task GetByIdAsync(int id, bool includeEvents)
ResourceVersion retVal;
if (includeEvents)
{
- retVal = await DbContext.ResourceVersion.AsNoTracking()
+ retVal = await this.DbContext.ResourceVersion.AsNoTracking()
.Include(r => r.Resource)
.Include(r => r.Publication).AsNoTracking()
.Include(r => r.ResourceVersionKeyword).AsNoTracking()
@@ -121,7 +121,7 @@ public async Task GetByIdAsync(int id, bool includeEvents)
}
else
{
- retVal = await DbContext.ResourceVersion.AsNoTracking()
+ retVal = await this.DbContext.ResourceVersion.AsNoTracking()
.Include(r => r.Resource)
.Include(r => r.Publication).AsNoTracking()
.Include(r => r.ResourceVersionKeyword).AsNoTracking()
@@ -145,7 +145,7 @@ public async Task GetByIdAsync(int id, bool includeEvents)
/// The .
public async Task GetCurrentForResourceAsync(int resourceId)
{
- return await DbContext.ResourceVersion.AsNoTracking()
+ return await this.DbContext.ResourceVersion.AsNoTracking()
.Include(r => r.Resource)
.Include(r => r.Publication).AsNoTracking()
.Include(r => r.ResourceVersionKeyword).AsNoTracking()
@@ -168,7 +168,7 @@ public async Task GetCurrentForResourceAsync(int resourceId)
/// The .
public async Task GetCurrentResourceDetailsAsync(int resourceId)
{
- return await DbContext.ResourceVersion.AsNoTracking()
+ return await this.DbContext.ResourceVersion.AsNoTracking()
.Include(r => r.Resource)
.Include(r => r.Publication).AsNoTracking()
.Include(r => r.ResourceVersionKeyword).AsNoTracking()
@@ -192,7 +192,7 @@ public async Task GetCurrentResourceDetailsAsync(int resourceId
/// The .
public async Task GetByResourceVersionByIdAsync(int resourceVersionId)
{
- return await DbContext.ResourceVersion.OrderByDescending(r => r.Id).FirstOrDefaultAsync(x => x.Id == resourceVersionId);
+ return await this.DbContext.ResourceVersion.OrderByDescending(r => r.Id).FirstOrDefaultAsync(x => x.Id == resourceVersionId);
}
///
@@ -202,7 +202,7 @@ public async Task GetByResourceVersionByIdAsync(int resourceVer
/// The .
public async Task DoesDevIdExistsAync(string devId)
{
- return await DbContext.ResourceVersion.OrderByDescending(r => r.Id).FirstOrDefaultAsync(x => x.DevId == devId);
+ return await this.DbContext.ResourceVersion.OrderByDescending(r => r.Id).FirstOrDefaultAsync(x => x.DevId == devId);
}
///
@@ -212,7 +212,7 @@ public async Task DoesDevIdExistsAync(string devId)
/// The .
public async Task GetCurrentPublicationForResourceAsync(int resourceId)
{
- return await DbContext.ResourceVersion.AsNoTracking()
+ return await this.DbContext.ResourceVersion.AsNoTracking()
.Include(r => r.Resource)
.OrderByDescending(r => r.Id)
.FirstOrDefaultAsync(r => r.ResourceId == resourceId
@@ -232,7 +232,7 @@ public async Task> GetResourceCards(bool includeEvents)
if (includeEvents)
{
- retVal = await DbContext.ResourceVersion.AsNoTracking()
+ retVal = await this.DbContext.ResourceVersion.AsNoTracking()
.Include(r => r.Resource).AsNoTracking()
.Include(r => r.Publication).AsNoTracking()
.Include(r => r.ResourceVersionKeyword).AsNoTracking()
@@ -245,7 +245,7 @@ public async Task> GetResourceCards(bool includeEvents)
}
else
{
- retVal = await DbContext.ResourceVersion.AsNoTracking()
+ retVal = await this.DbContext.ResourceVersion.AsNoTracking()
.Include(r => r.Resource).AsNoTracking()
.Include(r => r.Publication).AsNoTracking()
.Include(r => r.ResourceVersionKeyword).AsNoTracking()
@@ -268,7 +268,7 @@ public async Task GetCurrentForResourceReferenceIdAsync(int res
{
ResourceVersion retVal = null;
- var or = DbContext.ResourceReference.OrderByDescending(r => r.Id).FirstOrDefault(x => x.OriginalResourceReferenceId == resourceReferenceId);
+ var or = this.DbContext.ResourceReference.OrderByDescending(r => r.Id).FirstOrDefault(x => x.OriginalResourceReferenceId == resourceReferenceId);
if (or != null)
{
@@ -287,7 +287,7 @@ public async Task GetCurrentResourceForResourceReferenceIdAsync
{
ResourceVersion retVal = null;
- var or = DbContext.ResourceReference.OrderByDescending(r => r.Id).FirstOrDefault(x => x.OriginalResourceReferenceId == resourceReferenceId);
+ var or = this.DbContext.ResourceReference.OrderByDescending(r => r.Id).FirstOrDefault(x => x.OriginalResourceReferenceId == resourceReferenceId);
if (or != null)
{
@@ -306,7 +306,7 @@ public async Task GetCurrentPublicationForResourceReferenceIdAs
{
ResourceVersion retVal = null;
- var rr = DbContext.ResourceReference.FirstOrDefault(x => x.OriginalResourceReferenceId == resourceReferenceId);
+ var rr = this.DbContext.ResourceReference.FirstOrDefault(x => x.OriginalResourceReferenceId == resourceReferenceId);
if (rr != null)
{
@@ -323,7 +323,7 @@ public async Task GetCurrentPublicationForResourceReferenceIdAs
/// The .
public async Task> GetResourceVersionsAsync(int resourceId)
{
- return await DbContext.ResourceVersion.AsNoTracking()
+ return await this.DbContext.ResourceVersion.AsNoTracking()
.Include(r => r.Resource).AsNoTracking()
.Include(r => r.Publication).AsNoTracking()
.Include(r => r.ResourceVersionKeyword).AsNoTracking()
@@ -344,7 +344,7 @@ public async Task> GetResourceVersionsAsync(int resourceId
/// The .
public new async Task UpdateAsync(int userId, ResourceVersion resourceVersion)
{
- var resourceVersionUpdate = DbContext.ResourceVersion
+ var resourceVersionUpdate = this.DbContext.ResourceVersion
.SingleOrDefault(r => r.Id == resourceVersion.Id);
if (resourceVersionUpdate != null)
@@ -361,7 +361,7 @@ public async Task> GetResourceVersionsAsync(int resourceId
SetAuditFieldsForUpdate(userId, resourceVersionUpdate);
}
- await DbContext.SaveChangesAsync();
+ await this.DbContext.SaveChangesAsync();
}
///
@@ -372,7 +372,7 @@ public async Task> GetResourceVersionsAsync(int resourceId
/// The .
public async Task UpdateDevIdAsync(int userId, ResourceVersionDevIdViewModel resourceVersionDevIdViewModel)
{
- var resourceVersionUpdate = DbContext.ResourceVersion
+ var resourceVersionUpdate = this.DbContext.ResourceVersion
.SingleOrDefault(r => r.Id == resourceVersionDevIdViewModel.ResourceVersionId);
if (resourceVersionUpdate != null)
@@ -382,7 +382,7 @@ public async Task UpdateDevIdAsync(int userId, ResourceVersionDevIdViewModel res
SetAuditFieldsForUpdate(userId, resourceVersionUpdate);
}
- await DbContext.SaveChangesAsync();
+ await this.DbContext.SaveChangesAsync();
}
///
@@ -398,7 +398,7 @@ public void SetResourceType(int resourceVersionId, ResourceTypeEnum resourceType
var param2 = new SqlParameter("@p2", SqlDbType.Int) { Value = userId };
var param3 = new SqlParameter("@p3", SqlDbType.Int) { Value = TimezoneOffsetManager.UserTimezoneOffset ?? (object)DBNull.Value };
- DbContext.Database.ExecuteSqlRaw("resources.ResourceVersionSetResourceType @p0, @p1, @p2, @p3", param0, param1, param2, param3);
+ this.DbContext.Database.ExecuteSqlRaw("resources.ResourceVersionSetResourceType @p0, @p1, @p2, @p3", param0, param1, param2, param3);
}
///
@@ -408,7 +408,7 @@ public void SetResourceType(int resourceVersionId, ResourceTypeEnum resourceType
/// The .
public async Task GetResourceType(int resourceVersionId)
{
- return await DbContext.ResourceVersion
+ return await this.DbContext.ResourceVersion
.Include(rv => rv.Resource).AsNoTracking()
.Where(rv => rv.Id == resourceVersionId)
.Select(rv => rv.Resource.ResourceTypeEnum)
@@ -442,7 +442,7 @@ public int Publish(int resourceVersionId, bool isMajorRevision, string notes, Da
sql += ", @PublicationDate=@p6";
}
- DbContext.Database.ExecuteSqlRaw(sql, sqlParams);
+ this.DbContext.Database.ExecuteSqlRaw(sql, sqlParams);
return (int)param5.Value;
}
@@ -462,7 +462,7 @@ public void Unpublish(int resourceVersionId, string details, int userId)
var param2 = new SqlParameter("@p2", SqlDbType.Int) { Value = userId };
var param3 = new SqlParameter("@p3", SqlDbType.Int) { Value = TimezoneOffsetManager.UserTimezoneOffset ?? (object)DBNull.Value };
- DbContext.Database.ExecuteSqlRaw("resources.ResourceVersionUnpublish @p0, @p1, @p2, @p3", param0, param1, param2, param3);
+ this.DbContext.Database.ExecuteSqlRaw("resources.ResourceVersionUnpublish @p0, @p1, @p2, @p3", param0, param1, param2, param3);
}
///
@@ -476,7 +476,7 @@ public void RevertToDraft(int resourceVersionId, int userId)
var param1 = new SqlParameter("@p1", SqlDbType.Int) { Value = userId };
var param2 = new SqlParameter("@p2", SqlDbType.Int) { Value = TimezoneOffsetManager.UserTimezoneOffset ?? (object)DBNull.Value };
- DbContext.Database.ExecuteSqlRaw("resources.ResourceVersionRevertToDraft @p0, @p1, @p2", param0, param1, param2);
+ this.DbContext.Database.ExecuteSqlRaw("resources.ResourceVersionRevertToDraft @p0, @p1, @p2", param0, param1, param2);
}
///
@@ -490,7 +490,7 @@ public void Delete(int resourceVersionId, int userId)
var param1 = new SqlParameter("@p1", SqlDbType.Int) { Value = userId };
var param2 = new SqlParameter("@p2", SqlDbType.Int) { Value = TimezoneOffsetManager.UserTimezoneOffset ?? (object)DBNull.Value };
- DbContext.Database.ExecuteSqlRaw("resources.ResourceVersionDelete @p0, @p1, @p2", param0, param1, param2);
+ this.DbContext.Database.ExecuteSqlRaw("resources.ResourceVersionDelete @p0, @p1, @p2", param0, param1, param2);
}
///
@@ -501,7 +501,7 @@ public void Delete(int resourceVersionId, int userId)
/// The .
public Task DoesVersionExist(int resourceId, VersionStatusEnum status)
{
- return DbContext.ResourceVersion.AnyAsync(rv => rv.ResourceId == resourceId && rv.VersionStatusEnum == status);
+ return this.DbContext.ResourceVersion.AnyAsync(rv => rv.ResourceId == resourceId && rv.VersionStatusEnum == status);
}
///
@@ -517,7 +517,7 @@ public async Task CreateNextVersionAsync(int resourceId, int userId)
var param2 = new SqlParameter("@p2", SqlDbType.Int) { Value = TimezoneOffsetManager.UserTimezoneOffset ?? (object)DBNull.Value };
var param3 = new SqlParameter("@p3", SqlDbType.Int) { Direction = ParameterDirection.Output };
- await DbContext.Database.ExecuteSqlRawAsync("resources.ResourceVersionCreateNext @p0, @p1, @p2, @p3 output", param0, param1, param2, param3);
+ await this.DbContext.Database.ExecuteSqlRawAsync("resources.ResourceVersionCreateNext @p0, @p1, @p2, @p3 output", param0, param1, param2, param3);
return (int)param3.Value;
}
@@ -535,7 +535,7 @@ public async Task CreateDuplicateVersionAsync(int resourceId, int userId)
var param2 = new SqlParameter("@p2", SqlDbType.Int) { Value = TimezoneOffsetManager.UserTimezoneOffset ?? (object)DBNull.Value };
var param3 = new SqlParameter("@p3", SqlDbType.Int) { Direction = ParameterDirection.Output };
- await DbContext.Database.ExecuteSqlRawAsync("resources.ResourceVersionCreateDuplicate @p0, @p1, @p2, @p3 output", param0, param1, param2, param3);
+ await this.DbContext.Database.ExecuteSqlRawAsync("resources.ResourceVersionCreateDuplicate @p0, @p1, @p2, @p3 output", param0, param1, param2, param3);
return (int)param3.Value;
}
@@ -567,7 +567,7 @@ public async Task CreateDuplicateVersionAsync(int resourceId, int userId)
//// var param4 = new SqlParameter("@p4", SqlDbType.DateTimeOffset) { Value = activityStart };
//// var param5 = new SqlParameter("@p5", SqlDbType.DateTimeOffset) { Value = activityEnd };
- //// this.DbContext.Database.ExecuteSqlCommand("activity.ResourceActivityCreate @p0, @p1, @p2, @p3, @p4, @p5", param0, param1, param2, param3, param4, param5);
+ //// this.this.DbContext.Database.ExecuteSqlCommand("activity.ResourceActivityCreate @p0, @p1, @p2, @p3, @p4, @p5", param0, param1, param2, param3, param4, param5);
////}
///
@@ -578,7 +578,7 @@ public async Task CreateDuplicateVersionAsync(int resourceId, int userId)
/// A boolean.
public async Task HasUserCompletedActivity(int userId, int resourceVersionId)
{
- return await DbContext.ResourceActivity.AnyAsync(x => x.UserId == userId && x.ResourceVersionId == resourceVersionId);
+ return await this.DbContext.ResourceActivity.AnyAsync(x => x.UserId == userId && x.ResourceVersionId == resourceVersionId);
}
///
@@ -592,7 +592,7 @@ public void SubmitForPublishing(int resourceVersionId, int userId)
var param1 = new SqlParameter("@p1", SqlDbType.Int) { Value = userId };
var param2 = new SqlParameter("@p2", SqlDbType.Int) { Value = TimezoneOffsetManager.UserTimezoneOffset ?? (object)DBNull.Value };
- DbContext.Database.ExecuteSqlRaw("resources.ResourceVersionSubmitForPublishing @p0, @p1, @p2", param0, param1, param2);
+ this.DbContext.Database.ExecuteSqlRaw("resources.ResourceVersionSubmitForPublishing @p0, @p1, @p2", param0, param1, param2);
}
///
@@ -605,7 +605,7 @@ public void Publishing(int resourceVersionId, int userId)
var param0 = new SqlParameter("@p0", SqlDbType.Int) { Value = resourceVersionId };
var param1 = new SqlParameter("@p1", SqlDbType.Int) { Value = userId };
- DbContext.Database.ExecuteSqlRaw("resources.ResourceVersionPublishing @p0, @p1", param0, param1);
+ this.DbContext.Database.ExecuteSqlRaw("resources.ResourceVersionPublishing @p0, @p1", param0, param1);
}
///
@@ -618,7 +618,7 @@ public void FailedToPublish(int resourceVersionId, int userId)
var param0 = new SqlParameter("@p0", SqlDbType.Int) { Value = resourceVersionId };
var param1 = new SqlParameter("@p1", SqlDbType.Int) { Value = userId };
- DbContext.Database.ExecuteSqlRaw("resources.ResourceVersionFailedToPublish @p0, @p1", param0, param1);
+ this.DbContext.Database.ExecuteSqlRaw("resources.ResourceVersionFailedToPublish @p0, @p1", param0, param1);
}
///
@@ -636,7 +636,7 @@ public void CreateResourceVersionEvent(int resourceVersionId, ResourceVersionEve
var param3 = new SqlParameter("@p3", SqlDbType.Int) { Value = userId };
var param4 = new SqlParameter("@p4", SqlDbType.Int) { Value = TimezoneOffsetManager.UserTimezoneOffset ?? (object)DBNull.Value };
- DbContext.Database.ExecuteSqlRaw("resources.ResourceVersionEventCreate @p0, @p1, @p2, @p3, @p4", param0, param1, param2, param3, param4);
+ this.DbContext.Database.ExecuteSqlRaw("resources.ResourceVersionEventCreate @p0, @p1, @p2, @p3, @p4", param0, param1, param2, param3, param4);
}
///
@@ -658,7 +658,7 @@ public MyContributionsTotalsViewModel GetMyContributionTotals(int catalogueNodeI
var param8 = new SqlParameter("@UnpublishedCount", SqlDbType.Int) { Direction = ParameterDirection.Output };
var param9 = new SqlParameter("@UserUnpublishedCount", SqlDbType.Int) { Direction = ParameterDirection.Output };
- DbContext.Database.ExecuteSqlRaw("resources.GetContributionTotals @catalogueNodeId, @userId, @ActionRequiredCount output, @UserActionRequiredCount output, @DraftCount output, @UserDraftCount output, @PublishedCount output, @UserPublishedCount output, @UnpublishedCount output, @UserUnpublishedCount output", param0, param1, param2, param3, param4, param5, param6, param7, param8, param9);
+ this.DbContext.Database.ExecuteSqlRaw("resources.GetContributionTotals @catalogueNodeId, @userId, @ActionRequiredCount output, @UserActionRequiredCount output, @DraftCount output, @UserDraftCount output, @PublishedCount output, @UserPublishedCount output, @UnpublishedCount output, @UserUnpublishedCount output", param0, param1, param2, param3, param4, param5, param6, param7, param8, param9);
var myContributionsTotalsViewModel = new MyContributionsTotalsViewModel();
@@ -711,7 +711,7 @@ public List GetContributions(int userId, ResourceContri
sql += " @catalogueNodeId, @userId, @offset, @take, @restrictToCurrentUser";
- var contributions = DbContext.ResourceContributionDto.FromSqlRaw(sql, param0, param1, param2, param3, param4).ToList();
+ var contributions = this.DbContext.ResourceContributionDto.FromSqlRaw(sql, param0, param1, param2, param3, param4).ToList();
return contributions;
}
@@ -732,22 +732,22 @@ public List GetContributions(int userId, ResourceContri
switch (dashboardType)
{
case "my-certificates":
- dashboardResources = DbContext.DashboardResourceDto.FromSqlRaw("resources.GetMyLearningCertificatesDashboardResources @userId, @pageNumber, @totalRows output", param0, param1, param2).ToList();
+ dashboardResources = this.DbContext.DashboardResourceDto.FromSqlRaw("resources.GetMyLearningCertificatesDashboardResources @userId, @pageNumber, @totalRows output", param0, param1, param2).ToList();
break;
case "my-recent-completed":
- dashboardResources = DbContext.DashboardResourceDto.FromSqlRaw("resources.GetMyRecentCompletedDashboardResources @userId, @pageNumber, @totalRows output", param0, param1, param2).ToList();
+ dashboardResources = this.DbContext.DashboardResourceDto.FromSqlRaw("resources.GetMyRecentCompletedDashboardResources @userId, @pageNumber, @totalRows output", param0, param1, param2).ToList();
break;
case "my-in-progress":
- dashboardResources = DbContext.DashboardResourceDto.FromSqlRaw("resources.GetMyInProgressDashboardResources @userId, @pageNumber, @totalRows output", param0, param1, param2).ToList();
+ dashboardResources = this.DbContext.DashboardResourceDto.FromSqlRaw("resources.GetMyInProgressDashboardResources @userId, @pageNumber, @totalRows output", param0, param1, param2).ToList();
break;
case "recent-resources":
- dashboardResources = DbContext.DashboardResourceDto.FromSqlRaw("resources.GetRecentDashboardResources @userId, @pageNumber, @totalRows output", param0, param1, param2).ToList();
+ dashboardResources = this.DbContext.DashboardResourceDto.FromSqlRaw("resources.GetRecentDashboardResources @userId, @pageNumber, @totalRows output", param0, param1, param2).ToList();
break;
case "rated-resources":
- dashboardResources = DbContext.DashboardResourceDto.FromSqlRaw("resources.GetRatedDashboardResources @userId, @pageNumber, @totalRows output", param0, param1, param2).ToList();
+ dashboardResources = this.DbContext.DashboardResourceDto.FromSqlRaw("resources.GetRatedDashboardResources @userId, @pageNumber, @totalRows output", param0, param1, param2).ToList();
break;
case "popular-resources":
- dashboardResources = DbContext.DashboardResourceDto.FromSqlRaw("resources.GetPopularDashboardResources @userId, @pageNumber, @totalRows output", param0, param1, param2).ToList();
+ dashboardResources = this.DbContext.DashboardResourceDto.FromSqlRaw("resources.GetPopularDashboardResources @userId, @pageNumber, @totalRows output", param0, param1, param2).ToList();
break;
}
@@ -773,7 +773,7 @@ public async Task FractionalDuplication(int userId, int sourceBlockCollecti
var param3 = new SqlParameter("@p3", SqlDbType.Int) { Value = destinationBlockCollectionId };
var param2 = new SqlParameter("@p2", SqlDbType.Structured) { Value = ids, TypeName = "resources.IDList" };
var param5 = new SqlParameter("@p5", SqlDbType.Int) { Direction = ParameterDirection.Output };
- await DbContext.Database.ExecuteSqlRawAsync(
+ await this.DbContext.Database.ExecuteSqlRawAsync(
"resources.BlockCollectionWithBlocksCreateDuplicate @p0, @p1, @p2, @p3, @p4, @p5 output", param0, param1, param2, param3, param4, param5);
return param5.Value == DBNull.Value ? -1 : (int)param5.Value;
}
@@ -791,7 +791,7 @@ public async Task GetExternalContentDetails(int
var param0 = new SqlParameter("@resourceVersionId", SqlDbType.Int) { Value = resourceVersionId };
var param1 = new SqlParameter("@userId", SqlDbType.Int) { Value = userId };
- var retVal = await DbContext.ExternalContentDetailsViewModel.FromSqlRaw("[resources].[GetExternalContentDetails] @resourceVersionId, @userId", param0, param1).AsNoTracking().ToListAsync();
+ var retVal = await this.DbContext.ExternalContentDetailsViewModel.FromSqlRaw("[resources].[GetExternalContentDetails] @resourceVersionId, @userId", param0, param1).AsNoTracking().ToListAsync();
ExternalContentDetailsViewModel externalContentDetailsViewModel = retVal.AsEnumerable().FirstOrDefault();
return externalContentDetailsViewModel;
}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/ResourceVersionValidationResultRepository.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/ResourceVersionValidationResultRepository.cs
index edeb8a4c6..f6d06a03a 100644
--- a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/ResourceVersionValidationResultRepository.cs
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Resources/ResourceVersionValidationResultRepository.cs
@@ -58,7 +58,7 @@ public async Task GetByResourceVersionIdAsync(i
.Include(r => r.ResourceVersion).AsNoTracking()
.Include(r => r.ResourceVersionValidationRuleResults).AsNoTracking()
.Include(r => r.CreateUser).AsNoTracking()
- .Where(r => r.ResourceVersionId == resourceVersionId && r.ResourceVersion.VersionStatusEnum == LearningHub.Nhs.Models.Enums.VersionStatusEnum.FailedToPublish)
+ .Where(r => r.ResourceVersionId == resourceVersionId && r.ResourceVersion.VersionStatusEnum == Nhs.Models.Enums.VersionStatusEnum.FailedToPublish)
.OrderByDescending(r => r.Id)
.FirstOrDefaultAsync();
}
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/UserNotificationRepository.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/UserNotificationRepository.cs
new file mode 100644
index 000000000..02e67126a
--- /dev/null
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/UserNotificationRepository.cs
@@ -0,0 +1,106 @@
+namespace LearningHub.Nhs.OpenApi.Repositories.Repositories
+{
+ using System;
+ using System.Linq;
+ using System.Threading.Tasks;
+ using LearningHub.Nhs.Models.Entities;
+ using LearningHub.Nhs.Models.Enums;
+ using LearningHub.Nhs.OpenApi.Repositories.EntityFramework;
+ using LearningHub.Nhs.OpenApi.Repositories.Interface.Repositories;
+ using Microsoft.EntityFrameworkCore;
+
+ ///
+ /// The user notification repository.
+ ///
+ public class UserNotificationRepository : GenericRepository, IUserNotificationRepository
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The db context.
+ /// The Timezone offset manager.
+ public UserNotificationRepository(LearningHubDbContext dbContext, ITimezoneOffsetManager tzOffsetManager)
+ : base(dbContext, tzOffsetManager)
+ {
+ }
+
+ ///
+ /// The get by id async.
+ ///
+ /// The id.
+ /// The .
+ public async Task GetByIdAsync(int id)
+ {
+ return await DbContext.UserNotification
+ .Where(n => n.Id == id).SingleOrDefaultAsync();
+ }
+
+ ///
+ /// The get user unread notification count async.
+ ///
+ /// The user id.
+ /// The .
+ public async Task GetUserUnreadNotificationCountAsync(int userId)
+ {
+ return await GetActiveNotifications(userId, DateTimeOffset.Now)
+ .Where(n => !n.UserNotification.ReadOnDate.HasValue)
+ .CountAsync();
+ }
+
+ ///
+ /// The get all non dismissed.
+ ///
+ /// The user id.
+ /// Notification priority type.
+ /// The sort column.
+ /// The sort direction.
+ /// The .
+ public IQueryable GetAllNonDismissed(int userId, NotificationPriorityEnum priorityType, string sortColumn = "", string sortDirection = "")
+ {
+ var query = GetActiveNotifications(userId, DateTimeOffset.Now)
+ .Where(n => n.Notification.NotificationPriorityEnum == priorityType);
+
+ if (!string.IsNullOrWhiteSpace(sortColumn) && !string.IsNullOrWhiteSpace(sortDirection))
+ {
+ switch (sortColumn)
+ {
+ case "date":
+ return sortDirection == "A" ? query.OrderBy(n => n.Notification.StartDate) : query.OrderByDescending(n => n.Notification.StartDate);
+ default:
+ throw new NotImplementedException($"Sorting for column:{sortColumn} on notifications not implemented.");
+ }
+ }
+
+ return query.OrderByDescending(n => n.Notification.StartDate);
+ }
+
+ ///
+ /// The get by notification and user id async.
+ ///
+ /// The user id.
+ /// The notification id.
+ /// The .
+ public async Task GetByNotificationAndUserIdAsync(int userId, int notificationId)
+ {
+ return await DbContext.UserNotification
+ .Include(n => n.AmendUser)
+ .Include(n => n.CreateUser)
+ .Include(n => n.User)
+ .Include(n => n.Notification)
+ .Where(n => n.NotificationId == notificationId && n.UserId == userId).SingleOrDefaultAsync();
+ }
+
+ private IQueryable GetActiveNotifications(int userId, DateTimeOffset now)
+ {
+ return from n in DbContext.Notification
+ join un in DbContext.UserNotification
+ on new { n.Id, UserId = userId }
+ equals new { Id = un.NotificationId, un.UserId } into list
+ from un in list.DefaultIfEmpty()
+ where now >= n.StartDate && now <= n.EndDate
+ && (n.IsUserSpecific == false || un.UserId == userId)
+ && (un == null || un.Dismissed == false)
+ select new UserSpecificNotification { Notification = n, UserNotification = un };
+ }
+ }
+}
\ No newline at end of file
diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Startup.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Startup.cs
index f6d13500b..3a32a35f6 100644
--- a/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Startup.cs
+++ b/OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Startup.cs
@@ -51,6 +51,8 @@ private static void AddRepositoryImplementations(this IServiceCollection service
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
// Resources
services.AddScoped();
@@ -69,11 +71,13 @@ private static void AddRepositoryImplementations(this IServiceCollection service
services.AddScoped();
services.AddScoped();
services.AddScoped();
- services.AddScoped();
+ services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped