2020-07-13 15:58:59 -04:00
|
|
|
|
using System;
|
2020-08-19 13:35:17 -04:00
|
|
|
|
using System.Collections.Generic;
|
2020-07-13 15:58:59 -04:00
|
|
|
|
using System.Data;
|
|
|
|
|
|
using System.Data.SqlClient;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
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-07-13 15:58:59 -04:00
|
|
|
|
using Dapper;
|
|
|
|
|
|
|
2022-01-11 10:40:51 +01:00
|
|
|
|
namespace Bit.Infrastructure.Dapper.Repositories
|
2020-07-13 15:58:59 -04:00
|
|
|
|
{
|
|
|
|
|
|
public class SsoConfigRepository : Repository<SsoConfig, long>, ISsoConfigRepository
|
|
|
|
|
|
{
|
|
|
|
|
|
public SsoConfigRepository(GlobalSettings globalSettings)
|
|
|
|
|
|
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
public SsoConfigRepository(string connectionString, string readOnlyConnectionString)
|
|
|
|
|
|
: base(connectionString, readOnlyConnectionString)
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<SsoConfig> GetByOrganizationIdAsync(Guid organizationId)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
|
|
|
|
{
|
|
|
|
|
|
var results = await connection.QueryAsync<SsoConfig>(
|
|
|
|
|
|
$"[{Schema}].[{Table}_ReadByOrganizationId]",
|
|
|
|
|
|
new { OrganizationId = organizationId },
|
|
|
|
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
|
|
|
|
|
|
|
|
return results.SingleOrDefault();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<SsoConfig> GetByIdentifierAsync(string identifier)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
|
|
|
|
{
|
|
|
|
|
|
var results = await connection.QueryAsync<SsoConfig>(
|
|
|
|
|
|
$"[{Schema}].[{Table}_ReadByIdentifier]",
|
|
|
|
|
|
new { Identifier = identifier },
|
|
|
|
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
|
|
|
|
|
|
|
|
return results.SingleOrDefault();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-08-19 13:35:17 -04:00
|
|
|
|
|
|
|
|
|
|
public async Task<ICollection<SsoConfig>> GetManyByRevisionNotBeforeDate(DateTime? notBefore)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
|
|
|
|
{
|
|
|
|
|
|
var results = await connection.QueryAsync<SsoConfig>(
|
|
|
|
|
|
$"[{Schema}].[{Table}_ReadManyByNotBeforeRevisionDate]",
|
|
|
|
|
|
new { NotBefore = notBefore },
|
|
|
|
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
|
|
|
|
|
|
|
|
return results.ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-07-13 15:58:59 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|