2022-06-29 19:46:41 -04:00
|
|
|
|
using System.Data;
|
2020-08-26 14:12:04 -04:00
|
|
|
|
using System.Data.SqlClient;
|
2022-01-11 10:40:51 +01:00
|
|
|
|
using Bit.Core.Entities;
|
|
|
|
|
|
using Bit.Core.Repositories;
|
2021-02-22 15:35:16 -06:00
|
|
|
|
using Bit.Core.Settings;
|
2020-08-26 14:12:04 -04:00
|
|
|
|
using Dapper;
|
2020-07-28 10:03:09 -04:00
|
|
|
|
|
2022-01-11 10:40:51 +01:00
|
|
|
|
namespace Bit.Infrastructure.Dapper.Repositories;
|
2022-08-29 14:53:16 -04:00
|
|
|
|
|
2022-01-11 10:40:51 +01:00
|
|
|
|
public class SsoUserRepository : Repository<SsoUser, long>, ISsoUserRepository
|
2020-07-28 10:03:09 -04:00
|
|
|
|
{
|
|
|
|
|
|
public SsoUserRepository(GlobalSettings globalSettings)
|
|
|
|
|
|
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
public SsoUserRepository(string connectionString, string readOnlyConnectionString)
|
|
|
|
|
|
: base(connectionString, readOnlyConnectionString)
|
|
|
|
|
|
{ }
|
2020-08-26 14:12:04 -04:00
|
|
|
|
|
|
|
|
|
|
public async Task DeleteAsync(Guid userId, Guid? organizationId)
|
2022-08-29 14:53:16 -04:00
|
|
|
|
{
|
2020-08-26 14:12:04 -04:00
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
|
|
|
|
{
|
|
|
|
|
|
var results = await connection.ExecuteAsync(
|
|
|
|
|
|
$"[{Schema}].[SsoUser_Delete]",
|
|
|
|
|
|
new { UserId = userId, OrganizationId = organizationId },
|
|
|
|
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
|
|
}
|
2022-08-29 14:53:16 -04:00
|
|
|
|
}
|
2021-09-04 00:54:41 +10:00
|
|
|
|
|
|
|
|
|
|
public async Task<SsoUser> GetByUserIdOrganizationIdAsync(Guid organizationId, Guid userId)
|
2022-08-29 14:53:16 -04:00
|
|
|
|
{
|
2021-09-04 00:54:41 +10:00
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
|
|
|
|
{
|
|
|
|
|
|
var results = await connection.QueryAsync<SsoUser>(
|
|
|
|
|
|
$"[{Schema}].[SsoUser_ReadByUserIdOrganizationId]",
|
|
|
|
|
|
new { UserId = userId, OrganizationId = organizationId },
|
|
|
|
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
|
|
|
|
|
|
|
|
return results.SingleOrDefault();
|
|
|
|
|
|
}
|
2020-07-28 10:03:09 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|