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

Revert filescoped (#2227)

* Revert "Add git blame entry (#2226)"

This reverts commit 239286737d.

* Revert "Turn on file scoped namespaces (#2225)"

This reverts commit 34fb4cca2a.
This commit is contained in:
Justin Baur
2022-08-29 15:53:48 -04:00
committed by GitHub
parent 239286737d
commit bae03feffe
1208 changed files with 74317 additions and 73126 deletions

View File

@ -4,137 +4,138 @@ 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
namespace Bit.Infrastructure.EntityFramework.Repositories
{
public OrganizationSponsorshipRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.OrganizationSponsorships)
{ }
public async Task<ICollection<Guid>> CreateManyAsync(IEnumerable<Core.Entities.OrganizationSponsorship> organizationSponsorships)
public class OrganizationSponsorshipRepository : Repository<Core.Entities.OrganizationSponsorship, OrganizationSponsorship, Guid>, IOrganizationSponsorshipRepository
{
if (!organizationSponsorships.Any())
{
return new List<Guid>();
}
public OrganizationSponsorshipRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.OrganizationSponsorships)
{ }
foreach (var organizationSponsorship in organizationSponsorships)
public async Task<ICollection<Guid>> CreateManyAsync(IEnumerable<Core.Entities.OrganizationSponsorship> organizationSponsorships)
{
organizationSponsorship.SetNewId();
}
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var entities = Mapper.Map<List<OrganizationUser>>(organizationSponsorships);
await dbContext.AddRangeAsync(entities);
await dbContext.SaveChangesAsync();
}
return organizationSponsorships.Select(u => u.Id).ToList();
}
public async Task ReplaceManyAsync(IEnumerable<Core.Entities.OrganizationSponsorship> organizationSponsorships)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
dbContext.UpdateRange(organizationSponsorships);
await dbContext.SaveChangesAsync();
}
}
public async Task UpsertManyAsync(IEnumerable<Core.Entities.OrganizationSponsorship> organizationSponsorships)
{
var createSponsorships = new List<Core.Entities.OrganizationSponsorship>();
var replaceSponsorships = new List<Core.Entities.OrganizationSponsorship>();
foreach (var organizationSponsorship in organizationSponsorships)
{
if (organizationSponsorship.Id.Equals(default))
if (!organizationSponsorships.Any())
{
createSponsorships.Add(organizationSponsorship);
return new List<Guid>();
}
else
foreach (var organizationSponsorship in organizationSponsorships)
{
replaceSponsorships.Add(organizationSponsorship);
organizationSponsorship.SetNewId();
}
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var entities = Mapper.Map<List<OrganizationUser>>(organizationSponsorships);
await dbContext.AddRangeAsync(entities);
await dbContext.SaveChangesAsync();
}
return organizationSponsorships.Select(u => u.Id).ToList();
}
public async Task ReplaceManyAsync(IEnumerable<Core.Entities.OrganizationSponsorship> organizationSponsorships)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
dbContext.UpdateRange(organizationSponsorships);
await dbContext.SaveChangesAsync();
}
}
await CreateManyAsync(createSponsorships);
await ReplaceManyAsync(replaceSponsorships);
}
public async Task DeleteManyAsync(IEnumerable<Guid> organizationSponsorshipIds)
{
using (var scope = ServiceScopeFactory.CreateScope())
public async Task UpsertManyAsync(IEnumerable<Core.Entities.OrganizationSponsorship> organizationSponsorships)
{
var dbContext = GetDatabaseContext(scope);
var entities = await dbContext.OrganizationSponsorships
.Where(os => organizationSponsorshipIds.Contains(os.Id))
.ToListAsync();
var createSponsorships = new List<Core.Entities.OrganizationSponsorship>();
var replaceSponsorships = new List<Core.Entities.OrganizationSponsorship>();
foreach (var organizationSponsorship in organizationSponsorships)
{
if (organizationSponsorship.Id.Equals(default))
{
createSponsorships.Add(organizationSponsorship);
}
else
{
replaceSponsorships.Add(organizationSponsorship);
}
}
dbContext.OrganizationSponsorships.RemoveRange(entities);
await dbContext.SaveChangesAsync();
await CreateManyAsync(createSponsorships);
await ReplaceManyAsync(replaceSponsorships);
}
}
public async Task<Core.Entities.OrganizationSponsorship> GetByOfferedToEmailAsync(string email)
{
using (var scope = ServiceScopeFactory.CreateScope())
public async Task DeleteManyAsync(IEnumerable<Guid> organizationSponsorshipIds)
{
var dbContext = GetDatabaseContext(scope);
var orgSponsorship = await GetDbSet(dbContext).Where(e => e.OfferedToEmail == email)
.FirstOrDefaultAsync();
return orgSponsorship;
}
}
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var entities = await dbContext.OrganizationSponsorships
.Where(os => organizationSponsorshipIds.Contains(os.Id))
.ToListAsync();
public async Task<Core.Entities.OrganizationSponsorship> GetBySponsoredOrganizationIdAsync(Guid sponsoredOrganizationId)
{
using (var scope = ServiceScopeFactory.CreateScope())
dbContext.OrganizationSponsorships.RemoveRange(entities);
await dbContext.SaveChangesAsync();
}
}
public async Task<Core.Entities.OrganizationSponsorship> GetByOfferedToEmailAsync(string email)
{
var dbContext = GetDatabaseContext(scope);
var orgSponsorship = await GetDbSet(dbContext).Where(e => e.SponsoredOrganizationId == sponsoredOrganizationId)
.FirstOrDefaultAsync();
return orgSponsorship;
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> GetBySponsoringOrganizationUserIdAsync(Guid sponsoringOrganizationUserId)
{
using (var scope = ServiceScopeFactory.CreateScope())
public async Task<Core.Entities.OrganizationSponsorship> GetBySponsoredOrganizationIdAsync(Guid sponsoredOrganizationId)
{
var dbContext = GetDatabaseContext(scope);
var orgSponsorship = await GetDbSet(dbContext).Where(e => e.SponsoringOrganizationUserId == sponsoringOrganizationUserId)
.FirstOrDefaultAsync();
return orgSponsorship;
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<DateTime?> GetLatestSyncDateBySponsoringOrganizationIdAsync(Guid sponsoringOrganizationId)
{
using (var scope = ServiceScopeFactory.CreateScope())
public async Task<Core.Entities.OrganizationSponsorship> GetBySponsoringOrganizationUserIdAsync(Guid sponsoringOrganizationUserId)
{
var dbContext = GetDatabaseContext(scope);
return await GetDbSet(dbContext).Where(e => e.SponsoringOrganizationId == sponsoringOrganizationId && e.LastSyncDate != null)
.OrderByDescending(e => e.LastSyncDate)
.Select(e => e.LastSyncDate)
.FirstOrDefaultAsync();
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var orgSponsorship = await GetDbSet(dbContext).Where(e => e.SponsoringOrganizationUserId == sponsoringOrganizationUserId)
.FirstOrDefaultAsync();
return orgSponsorship;
}
}
}
public async Task<ICollection<Core.Entities.OrganizationSponsorship>> GetManyBySponsoringOrganizationAsync(Guid sponsoringOrganizationId)
{
using (var scope = ServiceScopeFactory.CreateScope())
public async Task<DateTime?> GetLatestSyncDateBySponsoringOrganizationIdAsync(Guid sponsoringOrganizationId)
{
var dbContext = GetDatabaseContext(scope);
var query = from os in dbContext.OrganizationSponsorships
where os.SponsoringOrganizationId == sponsoringOrganizationId
select os;
return Mapper.Map<List<Core.Entities.OrganizationSponsorship>>(await query.ToListAsync());
}
}
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
return await GetDbSet(dbContext).Where(e => e.SponsoringOrganizationId == sponsoringOrganizationId && e.LastSyncDate != null)
.OrderByDescending(e => e.LastSyncDate)
.Select(e => e.LastSyncDate)
.FirstOrDefaultAsync();
}
}
public async Task<ICollection<Core.Entities.OrganizationSponsorship>> GetManyBySponsoringOrganizationAsync(Guid sponsoringOrganizationId)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var query = from os in dbContext.OrganizationSponsorships
where os.SponsoringOrganizationId == sponsoringOrganizationId
select os;
return Mapper.Map<List<Core.Entities.OrganizationSponsorship>>(await query.ToListAsync());
}
}
}
}