1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-05 01:52:49 -05:00

Split out repositories to Infrastructure.Dapper / EntityFramework (#1759)

This commit is contained in:
Oscar Hinton
2022-01-11 10:40:51 +01:00
committed by GitHub
parent e2c6fc81f4
commit e4a10aae27
536 changed files with 1629 additions and 1589 deletions

View File

@ -0,0 +1,51 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using Bit.Core.Repositories;
using Bit.Infrastructure.EntityFramework.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Bit.Infrastructure.EntityFramework.Repositories
{
public class OrganizationSponsorshipRepository : Repository<Core.Entities.OrganizationSponsorship, OrganizationSponsorship, Guid>, IOrganizationSponsorshipRepository
{
public OrganizationSponsorshipRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.OrganizationSponsorships)
{ }
public async Task<Core.Entities.OrganizationSponsorship> GetByOfferedToEmailAsync(string email)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var orgSponsorship = await GetDbSet(dbContext).Where(e => e.OfferedToEmail == email)
.FirstOrDefaultAsync();
return orgSponsorship;
}
}
public async Task<Core.Entities.OrganizationSponsorship> GetBySponsoredOrganizationIdAsync(Guid sponsoredOrganizationId)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var orgSponsorship = await GetDbSet(dbContext).Where(e => e.SponsoredOrganizationId == sponsoredOrganizationId)
.FirstOrDefaultAsync();
return orgSponsorship;
}
}
public async Task<Core.Entities.OrganizationSponsorship> GetBySponsoringOrganizationUserIdAsync(Guid sponsoringOrganizationUserId)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var orgSponsorship = await GetDbSet(dbContext).Where(e => e.SponsoringOrganizationUserId == sponsoringOrganizationUserId)
.FirstOrDefaultAsync();
return orgSponsorship;
}
}
}
}