Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace LearningHub.Nhs.UserApi.Repository.Interface.LH
{
using System.Threading.Tasks;
using elfhHub.Nhs.Models.Entities;
using LearningHub.Nhs.Models.Entities.External;

/// <summary>
Expand All @@ -15,5 +16,12 @@ public interface IExternalSystemUserRepository : IGenericLHRepository<ExternalSy
/// <param name="externalSystemId">The external system id.</param>
/// <returns>The <see cref="ExternalSystemUser"/>.</returns>
Task<ExternalSystemUser> GetByIdAsync(int userId, int externalSystemId);

/// <summary>
/// Create External system user.
/// </summary>
/// <param name="userExternalSystem">The userExternalSystem.</param>
/// <returns>The <see cref="ExternalSystemUser"/>.</returns>
Task CreateExternalSystemUserAsync(ExternalSystemUser userExternalSystem);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
namespace LearningHub.Nhs.UserApi.Repository.LH
{
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using elfhHub.Nhs.Models.Entities;
using LearningHub.Nhs.Models.Entities.External;
using LearningHub.Nhs.UserApi.Repository;
using LearningHub.Nhs.UserApi.Repository.Interface.LH;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;

/// <summary>
Expand All @@ -30,5 +35,22 @@ public async Task<ExternalSystemUser> GetByIdAsync(int userId, int externalSyste
.AsNoTracking()
.FirstOrDefaultWithNoLockAsync();
}

/// <inheritdoc/>
public async Task CreateExternalSystemUserAsync(ExternalSystemUser userExternalSystem)
{
try
{
var param0 = new SqlParameter("@p0", SqlDbType.Int) { Value = userExternalSystem.UserId };
var param1 = new SqlParameter("@p1", SqlDbType.VarChar) { Value = userExternalSystem.ExternalSystemId };
var param2 = new SqlParameter("@p2", SqlDbType.VarChar) { Value = userExternalSystem.UserId };
var param3 = new SqlParameter("@p3", SqlDbType.Int) { Value = this.TimezoneOffsetManager.UserTimezoneOffset ?? (object)DBNull.Value };
await this.DbContext.Database.ExecuteSqlRawAsync("[external].ExternalSystemUserCreate @p0, @p1, @p2, @p3", param0, param1, param2, param3);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}
2 changes: 1 addition & 1 deletion LearningHub.Nhs.UserApi.Services/RegistrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public async Task LinkExistingUserToSso(int userId, int externalSystemId)
ExternalSystemId = externalSystemId,
};

await this.externalSystemUserRepository.CreateAsync(userId, userExternalSystem);
await this.externalSystemUserRepository.CreateExternalSystemUserAsync(userExternalSystem);
}

/// <inheritdoc/>
Expand Down
Loading