mirror of
https://github.com/bitwarden/server.git
synced 2025-07-05 18:12:48 -05:00
Split out repositories to Infrastructure.Dapper / EntityFramework (#1759)
This commit is contained in:
@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Settings;
|
||||
using Dapper;
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Repositories
|
||||
{
|
||||
public class OrganizationSponsorshipRepository : Repository<OrganizationSponsorship, Guid>, IOrganizationSponsorshipRepository
|
||||
{
|
||||
public OrganizationSponsorshipRepository(GlobalSettings globalSettings)
|
||||
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
||||
{ }
|
||||
|
||||
public OrganizationSponsorshipRepository(string connectionString, string readOnlyConnectionString)
|
||||
: base(connectionString, readOnlyConnectionString)
|
||||
{ }
|
||||
|
||||
public async Task<OrganizationSponsorship> GetBySponsoringOrganizationUserIdAsync(Guid sponsoringOrganizationUserId)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<OrganizationSponsorship>(
|
||||
"[dbo].[OrganizationSponsorship_ReadBySponsoringOrganizationUserId]",
|
||||
new
|
||||
{
|
||||
SponsoringOrganizationUserId = sponsoringOrganizationUserId
|
||||
},
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.SingleOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<OrganizationSponsorship> GetBySponsoredOrganizationIdAsync(Guid sponsoredOrganizationId)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<OrganizationSponsorship>(
|
||||
"[dbo].[OrganizationSponsorship_ReadBySponsoredOrganizationId]",
|
||||
new { SponsoredOrganizationId = sponsoredOrganizationId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.SingleOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<OrganizationSponsorship> GetByOfferedToEmailAsync(string offeredToEmail)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<OrganizationSponsorship>(
|
||||
"[dbo].[OrganizationSponsorship_ReadByOfferedToEmail]",
|
||||
new
|
||||
{
|
||||
OfferedToEmail = offeredToEmail
|
||||
},
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.SingleOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user